Convert part of string into char array in java – getchars(int, int, char[], int)

myStr.getChars(srcBeginIndex, srcEndIndex, dstCharArray, dstBeginIndex) is a java method which helps to get a part of the string into character array, this method accepts 4 parametes,

This method doesn’t return any value, rather it copies the part of the string in to the character array specified in the third parameter.

let’s see the implementation


In the above method, char[] mySubStr is infact a character array which contains the part of the string of myStr.

from index to 10 to 27 –

I have used String.valueOf(char[]), as mySubStr is a character array and need to convert to string for display in output.

Content posted is based on learning or working experience,
Share the post with others if find useful,
Any queries?, leave comments or discuss on our, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *