Java String getChars()

Java String getChars()

The java string getChars() method copies the content of this string into specified char array. There are 4 arguments passed in getChars() method. The signature of getChars() method is given below:

Signature

The signature or syntax of string getChars() method is given below:

  1. public void getChars(int srcBeginIndex, int srcEndIndex, char[] destination, int dstBeginIndex)

Returns

It doesn’t return any value.


Throws

It throws StringIndexOutOfBoundsException if beginIndex is greater than endIndex.


Java String getChars() method example

  1. public class StringGetCharsExample{
  2. public static void main(String args[]){
  3.  String str = new String(“hello javatpoint how r u”);
  4.       char[] ch = new char[10];
  5.       try{
  6.          str.getChars(616, ch, 0);
  7.          System.out.println(ch);
  8.       }catch(Exception ex){System.out.println(ex);}
  9. }}

Test it Now

Output:

javatpoint
java for beginners
java for beginners
java for beginners
CodSir //course // books
...

WikiSir

Java String getChars() The java string getChars() method copies the content of this string into specified char array. There are 4 arguments passed in getChars() method. The signature of getChars() method is given below: Signature The signature or syntax of string getChars() method is given below: public void getChars(int srcBeginIndex, int srcEndIndex, char[] destination, int dstBeginIndex) Returns It doesn’t return any value. Throws It throws StringIndexOutOfBoundsException […]

Tags:

....
...