- 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
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
To Continue Learning Please Login
Login with Google