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 229 views
2 answers 184 views
1 answer 152 views
2 answers 198 views
5 answers 499 views
2 answers 224 views
2 answers 327 views
...