Converting ArrayList of Characters to a String?

前端 未结 11 2157
清歌不尽
清歌不尽 2020-12-05 13:39

How to convert an ArrayList to a String in Java? The toString method returns it as [a,b,c] string - I wa

11条回答
  •  生来不讨喜
    2020-12-05 14:00

    How about this, Building the list

    List charsList = new ArrayList();
    charsList.add('h');
    charsList.add('e');
    charsList.add('l');
    charsList.add('l');
    charsList.add('o');
    

    Actual code to get String from List of Character:

    String word= new String();
    for(char c:charsList){
    word= word+ c; 
    }
    System.out.println(word);
    

    Still learning if there is a misake point out.

提交回复
热议问题