What is the shortest way to initialize List of strings in java?

后端 未结 7 909
无人共我
无人共我 2020-12-04 17:39

I am searching for the shortest way (in code) to initialize list of strings and array of strings, i.e. list/array containing \"s1\", \"s2\", \"s3\" string elements.

7条回答
  •  Happy的楠姐
    2020-12-04 18:14

    List stringList = Arrays.asList("s1", "s2", "s3");
    

    All these objects exists in the JDK.

    PS: As aioobe stated, this makes the list fixed-sized.

提交回复
热议问题