I would like to convert the string containing abc to a list of characters and a hashset of characters. How can I do that in Java ?
List
The most straightforward way is to use a for loop to add elements to a new List:
String abc = "abc";
List charList = new ArrayList();
for (char c : abc.toCharArray()) {
charList.add(c);
}
Similarly, for a Set:
String abc = "abc";
Set charSet = new HashSet();
for (char c : abc.toCharArray()) {
charSet.add(c);
}