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

后端 未结 7 930
无人共我
无人共我 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条回答
  •  醉话见心
    2020-12-04 17:59

    You can use the Arrays class in the standard Java API: http://download.oracle.com/javase/6/docs/api/java/util/Arrays.html#asList(T...)

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

    Be aware that the resultning list is fixed-size (you cannot add to it).

提交回复
热议问题