arraylist of characters 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: saving String character in arraylist
import java.util.*;
public class Basic_Practice2 {
public static void main(String[] args) {
String s = "Hello";
ArrayList<String> al = new ArrayList<String>();
for(int i = 0; i < s.length(); i++)
{
al.add(Character.toString(s.charAt(i)));
}
System.out.println(al);
}
}