Languages

Java create one element List in one line - how to do it?

1 points
Asked by:
Root-ssh
75570

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
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - friendly IT community for everyone.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join