java tutorial - Java Strings getChars() Method - tutorial java - java programming - learn java - java basics - java for beginners



Java strings getchars

Learn Java - Java tutorial - Java strings getchars - Java examples - Java programs

Description

Java Strings getChars() Method- it copies the characters from this string into an array of end symbols.

Syntax

The syntax of the method is:

public void getChars(int srcBegin, int srcEnd, char[] dst,  int dstBegin)
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • srcBegin is the index of the first character in the string to copy;
  • srcEnd is the index of the last character in the string to copy;
  • dst is the destination array;
  • dstBegin is the initial offset in the destination array.

Return value

  • In Java, getChars () does not return any value, but throws an IndexOutOfBoundsException.

Sample Code

import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str1 = new String("Welcome to wikitechy.com");
      char[] Str2 = new char[7];
      try {
         Str1.getChars(7, 14, Str2, 0);
         System.out.print("Copied Value = " );
         System.out.println(Str2 );
      }catch( Exception ex) {
         System.out.println("Raised exception...");
      }
   }
}
click below button to copy the code. By - java tutorial - team

Output

Copied Value =  to wik

Related Searches to Java Strings getChars() Method