Java getChars method with getBytes method

Java getChars method stores string data into character array. We can copy all string and also part of string.

Java getBytes method stores string data into byte array. We can find ASCII code from this function.

 

Let’s see example on java getChars method

 

class str8

{

                public static void main(String args[])

                {

                                String str1 = “Gandhinagar is State”;

                                String str2 = “Gujarat is City”;

                                char storeString[] = new char[50];

 

                                str1.getChars(0,14,storeString,0);

                                // 0 – start index of str1 -> G

                                // 14 – end index of str1 -> s

                                // storeString -> array name

                                // 0 – start index of storeString array

 

                                System.out.println(storeString);              

 

                                str2.getChars(10,15,storeString,15);

                                // 10 – start index of str2 -> _City

                                // 15 – end inde of str2 -> y

                                // storeString – char array

                                // 15 – inde of storestring array

 

                                System.out.println(storeString);

                }

}

 

Output:

Gandhinagar is

Gandhinagar is City

 

Video on getChars method


[sbscrbr_form]

If you have any query on blog example, you can directly comment us or subscribe our website


Earn Money Online

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

263total visits,4visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

EmailEmail
PrintPrint