Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Creating a string from a subset of the array elements in Java
To get a string from a subset of the character array elements, use the copyValueOf() method. This method returns a String that represents the character sequence in the array specified.
Here is our character array.
char[] ch = { 'T', 'E', 'S', 'T', 'I', 'N', 'G'};
Now, let us create a string from the subset of the above array elements.
String str = String.copyValueOf(ch, 4, 2);
Example
public class Demo {
public static void main(String[] args) {
char[] ch = { 'T', 'E', 'S', 'T', 'I', 'N', 'G'};
String str = String.copyValueOf(ch, 4, 2);
System.out.println(str);
}
}
Output
IN
Advertisements
