首页 > 代码库 > Java String、string[]、List初始化方法

Java String、string[]、List初始化方法

String初始化:

  1.String str = new String("string1");

  2.String str = "string1";

String[]初始化:

  1.String[] str = new String[5];

  2.String[] str = new String[]{"a", "b", "c", "d", "e"};

  3.String[] str = {"a", "b", "c", "d", "e"};

List初始化:

  1.List strList<String> = new ArrayList<String> ();

   strList.add("a");

   strList.add("b");

  2.List strList<String> = new ArrayList<String> (){

    {

      add("a");

      add("b");

    }//初始化块,在构造器之前执行。

   };

Java String、string[]、List初始化方法