您的位置:首页 > 其它

持有对象 练习12

2009-08-10 08:00 155 查看
将第一个表反序插入第二个表

import java.util.*;

public class Ex12 {

public static void main(String[] args) {

List<Integer> li1 =

new ArrayList<Integer>(Arrays.asList(0, 1, 2, 3, 4));

List<Integer> li2 =

new ArrayList<Integer>(Arrays.asList(5, 6, 7, 8, 9));

// start it1 at the end:

ListIterator<Integer> it1 = li1.listIterator(5);

ListIterator<Integer> it2 = li2.listIterator();

System.out.println("li1: " + li1);

System.out.println("li2: " + li2);

// now use it2 to re-set li2

while(it2.hasNext()) {

it2.next();

it2.set(it1.previous());

}

System.out.println("li1: " + li1);

System.out.println("li2: " + li2);

}

}





输出

G:/text/Holding>java Ex12

li1: [0, 1, 2, 3, 4]

li2: [5, 6, 7, 8, 9]

li1: [0, 1, 2, 3, 4]

li2: [4, 3, 2, 1, 0]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: