String getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) method in Java

The getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) method in Java copies characters from this string into the destination character array.

Syntax

Let us see the syntax,

getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)

Parameters

Let us see the parameters,

  • srcBegin− index of the first character in the string to copy
  • srcEnd− index after the last character in the string to copy
  • dst− destination array
  • dstBegin− start offset in the destination array

Example

The following is an example of getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin),

import java.io.*;

public class StudyopediaDemo {

   public static void main(String args[]) {
	 
     String message1 = new String("Australia is a country!");
     char[] message2 = new char[3];
	 
     try {
        message1.getChars(4, 7, message2, 0);
        System.out.println("Result: ");
        System.out.println(message2);
     } 
     catch (Exception e) {
        System.out.println("Exception!");
    }
  } 
}

Output

The following is the output,

Java String getchars method

byte[] getBytes(String charsetName)
String hashCode() method in Java
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment