双括号初始化理解及效率问题参考:双大括号初始化的理解和使用
package com.idark;
import java.util.ArrayList;
/**
* @description: Demo测试
* @author: iDark
* @create: 2018/8/3 14:57
* @email: 43352901@qq.com
*/
public class Demo {
public static void main(String[] args) {
//Method 1
ArrayList<String> lists1 = new ArrayList<String>();
lists1.add("test1");
lists1.add("test2");
//Method 2 , (double brace initialization)
ArrayList<String> lists2 = new ArrayList<String>(){{
add("test1");
add("test2");
}};
}
}