Convert Character array to string in Java

后端 未结 10 1999
野的像风
野的像风 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条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 17:28

    how about creating your own method that iterates through the list of Character array then appending each value to your new string.

    Something like this.

    public String convertToString(Character[] s) {
       String value;
    
       if (s == null) {
         return null;
       }
    
       Int length = s.length();
       for (int i = 0; i < length; i++) {
         value += s[i];
       }
    
       return value;
    } 
    

提交回复
热议问题