You are here: Home / Topics / getChars() method example in Java

getChars() method example in Java

Filed under: Java on 2023-08-23 18:49:57

// Program to explain the following String function :
// void getChars( int sourceStart, int sourceEnd,
// char target[], int targetStart )

class  MgetChars
{
public static void main( String args[ ] )
{
 char  ch[ ] = new char[4];
 String s1 = "Java Programming Examples."; 
 
 s1.getChars( 0, 4, ch, 0 );

 String s2 = new String( ch );

 System.out.println(  " Source : " + s1 );
 System.out.print( " Target : " );
 System.out.println( ch );

 System.out.println(" Source : " + s1);
 System.out.print(" Target : " + s2);
}
}


Output:

Source : Java Programming Examples.
Target : Java
Source : Java Programming Examples.
Target : Java


About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.