array list of characters 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: convert every character in string to arraylist jva
import java.util.ArrayList;
import java.util.List;
class Util
{
public static void main(String[] args)
{
String string = "Techie Delight";
List<Character> chars = new ArrayList<>();
for (char ch: string.toCharArray()) {
chars.add(ch);
}
System.out.println(chars);
}
}