char to arraylist 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: char array to arraylist java
myString.chars().mapToObj(c -> (char) c).collect(Collectors.toList());
Example 3: convert character arraylist to array
public char[] toArray(List<Character> list){
char[] toReturn = new char[list.size()];
int i = 0;
for(char c : list)
toReturn[i ++] = c;
return toReturn;
}