Languages

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

3 points
Asked by:
Kate_C
2854

How can I create List of Strings without using multile line code in java?

I have List<String> like below:

List<String> list = new ArrayList<>();
list.add("1");
list.add("2");
list.add("3");

Is it possible to do it in 1 line?

0 answers
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.