java:Conllection(List,set,get,map,subList)使用

list中的contains:是否包含指定元素

list中的SubList:  返回列表中指定的 fromIndex(包括 )和 toIndex(不包括)之间的部分视图。

List<String> addlist = new ArrayList<String>();
		addlist.add("hello");
		addlist.add(0, "hi");
		addlist.add("world");
		addlist.add("welcome");
		addlist.add("how");
		
		//是否包含指定元素
		System.out.println( addlist.contains("hi") );
		//是否包含指定元素
		System.out.println( addlist.contains("how") );
		
		//返回列表中指定的index(包括)和endIndex(不包括)之间的数据
		System.out.println( addlist.subList(0, 2) );
		//返回列表中指定的index(包括)和endIndex(不包括)之间的数据
		System.out.println( addlist.subList(2, 5));
		

  

原文地址:https://www.cnblogs.com/achengmu/p/7467669.html