Convert Character array to string in Java

后端 未结 10 2003
野的像风
野的像风 2021-02-05 16:59

I have a Character array (not char array) and I want to convert it into a string by combining all the Characters in the array.

I have tried the following f

10条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 17:23

    Probably an overkill, but on Java 8 you could do this:

    Character[] chars = {new Character('a'),new Character('b'),new Character('c')};
    
    String value = Arrays.stream(chars)
                    .map(Object::toString)
                    .collect( Collectors.joining() );
    

提交回复
热议问题