WEB开发网
开发学院WEB开发Jsp java_util_test 阅读

java_util_test

 2008-01-05 09:00:17 来源:WEB开发网   
核心提示:package com.diegoyun.apiLearning;import java.util.*;/** * User: diegoyun * Date: 2005-1-30 * Time: 19:03:29 */public final class UtilTutorial{ public static

package com.diegoyun.apiLearning;

import java.util.*;


/**
* User: diegoyun
* Date: 2005-1-30
* Time: 19:03:29
*/
public final class UtilTutorial
{
public static void collectionRetainTest()
{
System.out.PRintln("**********collectionRetainTest begin:");
Collection c1 = new ArrayList();
Collection c2 = new ArrayList();
c1.add("aaa");
c1.add("bbb");
c1.add("ccc");
c2.add("ddd");
c2.add("ccc");
c2.add("eee");
boolean isRetainSUCceed = false;
isRetainSucceed = c2.retainAll(c1);
System.out.println("isRetainSucceed = " + isRetainSucceed);
System.out.println("********** Print collection c2 values ");
for (Iterator iter = c2.iterator(); iter.hasNext();)
{
String s = (String) iter.next();
System.out.println("element = " + s);
}
System.out.println("**********collectionRetainTest end:");
}
public static void listIteratorTest(){
System.out.println("**********listIteratorTest begin:");
List list = new ArrayList();
list.add("aaa");
list.add("bbb");
list.add("ccc");

ListIterator iter = list.listIterator();
System.out.println("**************** Iterating List forward :");
while(iter.hasNext()){
String s = (String)iter.next();
System.out.println("**********element = " + s);
}
System.out.println("**************** Iterating List backward :");
while(iter.hasprevious()){
String s = (String)iter.previous();
System.out.println("**********element = " + s);
}
System.out.println("**************** Add element into List :");
while(iter.hasNext()){
int i = iter.nextIndex();
if (i==2)
iter.add("ddd");
String s = (String)iter.next();
System.out.println("**********element = " + s);
}
System.out.println("**************** Iterating List backward after add element:");
while(iter.hasPrevious()){

Tags:java util test

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接