How to convert ArrayList of characters to a string in Java

1 Answer

0 votes
import java.util.ArrayList;
import java.util.List;

public class MyClass {
    public static void main(String args[]) {
        List<Character> charsList = new ArrayList<Character>();
        
        charsList.add('j');
        charsList.add('a');
        charsList.add('v');
        charsList.add('a');
    
        StringBuilder sb = new StringBuilder(charsList.size());
        for (Character ch : charsList) {
            sb.append(ch);
        }
        String s = sb.toString();
        
        System.out.println(s);
    }
}




/*
run:

java

*/

 



answered Aug 28, 2021 by avibootz

Related questions

1 answer 363 views
2 answers 315 views
1 answer 260 views
2 answers 318 views
5 answers 740 views
2 answers 369 views
2 answers 451 views
...