一个Collections的例子 (视频下载) (全部书籍)
马克-to-win: 在操纵ArrayList里面的内容时, 通常我们利用Collections。Collections是集合框架中的一个工具类。可用来排序,反转ArrayList里面的内容。
例:1.1.3
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
public class TestMark_to_win {
public static void main(String args[]) {
ArrayList l = new ArrayList();
l.add("a");
l.add("c");
l.add("b");
l.add("d");
System.out.println(l + "\n");
Collections.reverse(l);
System.out.println(l + "\n");
Collections.sort(l);
System.out.println(l + "\n");
Iterator it = l.iterator();
String lll = "";
while (it.hasNext()) {
String kk = (String) it.next();
lll = lll + kk;
// if (kk.equals("jkc")) System.out.println("has jkc");
。。。。。。。。。。。。。。。。。
详情黏贴以下网址在地址栏后请进:http://www.mark-to-win.com/index.html?content=JavaBeginner/javaUrl.html&chapter=JavaBeginner/JavaBeginner7_web.html#DefinitionUsageOfCollections
java中Collections有什么用,举例说明?
猜你喜欢
转载自www.cnblogs.com/mark-to-win/p/9698341.html
今日推荐
周排行