日期:2014-05-20 浏览次数:20673 次
import java.util.ArrayList; import java.util.List; public class TestList { private List<String> list; private List<List<String>> mainList; public TestList(){ list = new ArrayList<String>(); mainList = new ArrayList<List<String>>(); } public static void main(String arg[]){ String[] mylist = {"sunday","monda","tuesday","wednesday","thurday","friday","saturday"}; TestList tl1 = new TestList(); for(String s : mylist) tl1.list.add(s);//这里为什么可以这样写? list是私有变量 可以对象点么?不解 tl1.mainList.add(tl1.list); //tl1.list.clear(); // here if clear then not getting the list // tl1.list = null; ///// but here to assign null still getting list tl1.list.clear(); System.out.println("after clear"); System.out.println("@@@@@@@@@======="+tl1.list); for(List<String> list : tl1.mainList){ for(String s : list){ System.out.println("*********"+s); } } } } =================================== clear 的时候结果为 after clear @@@@@@@@@=======[] ===================================null 的时候结果为 after clear @@@@@@@@@=======null *********sunday *********monda *********tuesday *********wednesday *********thurday *********friday *********saturday