- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Extracting a substring as an array of characters in Java
To extract a substring as an array of characters in Java, use the getChars() method.
Let’s say the following is our string and character array.
String str = "World is not enough!"; char[] chArr = new char[10];
Now, use the getChars() method to extract a substring.
str.getChars(13, 19, chArr, 0);
The above substring is an array of characters which can be displayed as shown in the complete example below −
Example
public class Demo { public static void main(String[] args) { String str = "World is not enough!"; char[] chArr = new char[10]; str.getChars(13, 19, chArr, 0); for(char res: chArr) { System.out.println(res); } } }
Output
e n o u g h
- Related Articles
- Extracting a substring using Linux bash
- Java Program to get the Characters in a String as an Array of Bytes
- Searching characters and substring in a String in Java
- Java Program to fill an array of characters from user input
- Longest Substring Without Repeating Characters in Python
- How to match the regex meta characters in java as literal characters.
- How to convert an array of characters into a string in C#?
- Largest Substring Between Two Equal Characters in a string in JavaScript
- Extracting each word from a string using Regex in Java
- JavaScript filter an array of strings, matching case insensitive substring?
- Program to count number of distinct characters of every substring of a string in Python
- Return an array with the number of nonoverlapping occurrences of substring in Python
- Display the position of a Substring in Java
- Count occurrences of a substring recursively in Java
- How to get a substring of a particular string in Java. Explain with an example.

Advertisements