Use Arrays
class in Java which will return you an ArrayList
:
final List<String> characters = Arrays.asList("+","-");
You will need a bit more work if you need a List<Character>
.
You can use Google guava as such:
ImmutableList<char> dirs = ImmutableList.of('+', '-', '*', '^');
May be this helps
List<String> l = Arrays.asList("+","-");
Assuming you have an ArrayList
that contains characters, you could do this:
List<Character> list = new ArrayList<Character>();
list.addAll(Arrays.asList('+', '-', '*', '^'));
You can use the asList
method with varargs to do this in one line:
java.util.Arrays.asList('+', '-', '*', '^');
If the list does not need to be modified further then this would already be enough. Otherwise you can pass it to the ArrayList constructor to create a mutable list:
new ArrayList(Arrays.asList('+', '-', '*', '^'));
Source: Stackoverflow.com