How do I copy char array to string?
Category: java.lang, viewed: 2292 time(s).
This examples shows how to copy all or some part of the character array.
package org.kodejava.example.lang; public class CharArrayCopyExample { public static void main(String[] args) { char[] data = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}; // // Copy all value in the char array and create a new string out of it. // String text = String.valueOf(data); System.out.println(text); // // Copy a sub array from the char array and create a new string. The // following line will just copy 5 characters starting from array index // of three. When the element copied is out side of the array index an // IndexOutOfBoundsException will be thrown. // text = String.copyValueOf(data, 3, 5); System.out.println(text); } } |
Can't find what you are looking for? Join our FORUMS and ask some questions!
Related Examples
- How do I read system property as an integer?
- How do I decode string to integer?
- How do I insert a string in the StringBuilder?
- How do I remove substring from StringBuilder?
- How do I reverse a string by word?
- How do I convert varargs to an array?
- How do I remove trailing white space from a string?
- How do I remove leading white space from a string?
- How do I create a method that accept varargs in Java?
- How do I know a class of an object?