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

java

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初始化方法 的全部内容, 来源链接: utcz.com/z/394864.html

回到顶部