Java String getChars() Method

Facebooktwitterredditpinterestlinkedinmailby feather

Java String getChars() method copies characters from current String to the destination character array .

Syntax:

Parameters:

srcBegin – index of the first character in the string to copy.

srcEnd index of the last character in the string to copy.

destination the destination array.

dstBegin – the start offset in the destination array

Return:

It doesn’t return any value

Throws:

It throws StringIndexOutOfBoundException  if any of the following is true:

  • srcBegin is negative.
  • srcBegin is greater than srcEnd
  • srcEnd is greater than the length of this string
  • dstBegin is negative
  • dstBegin+(srcEnd-srcBegin) is larger than destination.length

Java String getChars() Example 1

output:

Java String getChars() Example 2

Output:

Facebooktwitterredditpinterestlinkedinmailby feather

Leave a Comment