Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting String to "Character" array in Java

I want to convert a String to an array of objects of Character class but I am unable to perform the conversion. I know that I can convert a String to an array of primitive datatype type "char" with the toCharArray() method but it doesn't help in converting a String to an array of objects of Character type.

How would I go about doing so?

like image 978
kgd Avatar asked Apr 04 '12 06:04

kgd


People also ask

Can we convert a string to character array in Java?

The java string toCharArray() method converts this string into character array. It returns a newly created character array, its length is similar to this string and its contents are initialized with the characters of this string.

How do I convert a string array to an array in Java?

String class split(String regex) can be used to convert String to array in java. If you are working with java regular expression, you can also use Pattern class split(String regex) method.

Can you convert a string to an array?

We can also convert String to String array by using the toArray() method of the List class. It takes a list of type String as the input and converts each entity into a string array.


1 Answers

Use this:

String str = "testString"; char[] charArray = str.toCharArray(); Character[] charObjectArray = ArrayUtils.toObject(charArray); 
like image 67
Kuldeep Jain Avatar answered Sep 22 '22 14:09

Kuldeep Jain