Home >>Java String Methods >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().
void getChars(char dst[], int dstBegin) { System.arraycopy(value, 0, dst, dstBegin, value.length); }
public void getChars(int srcBeginIndex, int srcEndIndex, char[] destination, int dstBeginIndex)
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);
}
}
}