- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java String getChars() method example.
The getChars() method of a String class accepts four parameters namely −
- srcBegin − index of the first character in the string to copy.
- srcEnd − index after the last character in the string to copy.
- dst − the destination array.
- dstBegin − the start offset in the destination array.
Example
It copies all the characters of the current string to the destination character array.
import java.io.*; public class Test { public static void main(String args[]) { String Str1 = new String("Welcome to Tutorialspoint.com"); char[] Str2 = new char[7]; try { Str1.getChars(2, 9, Str2, 0); System.out.print("Copied Value = " ); System.out.println(Str2 ); } catch ( Exception ex) { System.out.println("Raised exception..."); } } }
Output
Copied Value = lcome t
- Related Articles
- Java String compareTo() Method example.
- Java String substring() Method example.
- Java String endsWith() method example.
- Java String equals() method example.
- Java String equalsIgnoreCase() method example.
- Java String format() method example.
- Java String getBytes() method example.
- Java String indexOf() method example.
- Java String intern() method example.
- Java String isEmpty() method example.
- Java String lastIndexOf() method example.
- Java String length() method example.
- Java String replace() method example.
- Java String split() method example.
- Java String startsWith() method example.

Advertisements