EN
Java create one element List in one line - how to do it?
0
answers
1
points
How can I create one element List of Strings in 1 line?
List<String> list = new ArrayList<>();
list.add("1");
Is is possible to do it in 1 line?
When I have method which would return this array, it'd take 3 lines:
public List<String> createList() {
List<String> list = new ArrayList<>();
list.add("1");
return list;
}
It'd be great if it could be done in 1 line instead of 3.
0 answers