Home >>Java String Methods >Java String getChars() method

Java String getChars() method

Java String getChars() method

Java getChars() method of the java string copies the contents of this string into defined char array. There are four arguments passed in method getChars().

Internal implementation

void getChars(char dst[], int dstBegin) 
{  
        System.arraycopy(value, 0, dst, dstBegin, value.length);  
}  

Signature

public void getChars(int srcBeginIndex, int srcEndIndex, char[] destination, int dstBeginIndex)  
String getChars() method example 1

public class StringGetCharsExample
{  
public static void main(String args[])
{  
 String strln1 = new String("hello world");  
      char[] ch = new char[5];  
      try
	  {  
         strln1.getChars(6, 11, ch, 0);  
         System.out.println(ch);  
      }
	  catch(Exception ex)
	  {
	  System.out.println(ex);
	  }  
}
} 

Output
World

No Sidebar ads