Java String getChars() with examples Last Updated : 04 Feb, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report The java string getChars() method copies characters from the given string into the destination character array.Syntax: public void getChars(int srhStartIndex, int srhEndIndex, char[] destArray, int destStartIndex) Parameters: srhStartIndex : Index of the first character in the string to copy. srhEndIndex : Index after the last character in the string to copy. destArray : Destination array where chars will get copied. destStartIndex : Index in the array starting from where the chars will be pushed into the array. Return: It does not return any value. Exception: StringIndexOutOfBoundsException - If srhStartIndex, srhEndIndex are not in proper range.Example : To show working of getChars() method java // Java program to demonstrate // working of getChars() method class Gfg1 { public static void main(String args[]) { String str = "Welcome! to GeeksforGeeks"; char[] destArray = new char[20]; try { str.getChars(12, 25, destArray, 0); System.out.println(destArray); } catch (Exception ex) { System.out.println(ex); } } } Output: GeeksforGeeks java // Java program to demonstrate // exception condition in // working of getChars() method class Gfg2 { public static void main(String args[]) { String str = "Welcome! to GeeksforGeeks"; char[] destArray = new char[20]; try { // Starting index 0 and ending index 24 str.getChars(12, 26, destArray, 0); System.out.println(destArray); } catch (Exception ex) { System.out.println(ex); } } } Output: java.lang.StringIndexOutOfBoundsException: String index out of range: 26 Comment More infoAdvertise with us Next Article ByteBuffer getChar() method in Java with Examples N Niraj_Pandey Follow Improve Article Tags : Java Java-Strings Java-lang package Java-Functions Practice Tags : JavaJava-Strings Similar Reads StringBuilder getChars() in Java with Examples The getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) method of StringBuilder class copies the characters starting at the given index:srcBegin to index:srcEnd-1 from String contained by StringBuilder into an array of char passed as parameter to function. The characters are copied from Str 3 min read StringBuffer getChars() method in Java with Examples The getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) method of StringBuffer class copies the characters starting at the index:srcBegin to index:srcEnd-1 from actual sequence into an array of char passed as parameter to function. The characters are copied into the array of char dst[] star 3 min read ByteBuffer getChar() method in Java with Examples getChar() The getChar() method of java.nio.ByteBuffer class is used to get method for reading a char value Reads the next two bytes at this buffer's current position, composing them into a char value according to the current byte order, and then increments the position by two. Syntax: public abstrac 6 min read StringBuilder charAt() in Java with Examples The charAt(int index) method of StringBuilder Class is used to return the character at the specified index of String contained by StringBuilder Object. The index value should lie between 0 and length()-1. Syntax: public char charAt(int index) Parameters: This method accepts one int type parameter in 3 min read Charset toString() method in Java with Examples The toString() method is a built-in method of the java.nio.charset returns a string which describes the charset involved. Syntax: public final String toString() Parameters: The function does not accepts any parameter. Return Value: The function returns a string describing this charset. Below is the 1 min read StringBuffer setCharAt() method in Java with Examples The setCharAt() method of StringBuffer class sets the character at the position index to character which is the value passed as parameter to method. This method returns a new sequence which is identical to old sequence only difference is a new character ch is present at position index in new sequenc 2 min read Like