what is the most optimial way to convert Arraylist<Integer> to char[]

user11000055 :

I am wondering is there anyways probably by stream API to convert

List<Integer> li = Arrays.asList(1,2,3,45,678); 

to char[] ch without going to an intermediate stage of String? I could not find one.

Vishwa Ratna :

I achieved the solution , but i had to have a intermediate String Transformation.

List<Integer> li = Arrays.asList(1,2,3,45,678); 
        String Str =li.toString();
        char [] ch = new char[Str.length()];
        for(int i=0;i<Str.length();i++)
        {
         ch[i] =    Str.charAt(i);
        }
        for(char cc:ch)
        {        
            System.out.print(cc);
        }

Output: [1, 2, 3, 45, 678]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=129459&siteId=1