how to create a arraylist of char in java code example
Example 1: arraylist of characters
import java.util.ArrayList;
public class Test{
String words = new String("HELLO GOODBYE!");
ArrayList<Character> sample = new ArrayList<Character>();
for(int i = 0; i<words.length(); i++){
sample.add(words.charAt(i));
}
}
Example 2: Arraylist string to character java
String str = "abcd...";
ArrayList<Character> chars = new ArrayList<Character>();
for (char c : str.toCharArray()) {
chars.add(c);
}