⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex7(3).java

📁 JAVA编程思想第四版英文原版习题答案. pdf原版的
💻 JAVA
字号:
// containers/Ex7.java
// TIJ4 Chapter Containers, Exercise 7, page 820
/* Create both an ArrayList and a LinkedList, and fill each using the
*  Countries.names() generator. Print each list using an ordinary 
* iterator, then insert one list into the other by using a ListIterator, 
* inserting at every other location. Now perform the insertion staring
* at the end of the first list and moving backwards.
*/
import java.util.*;
import net.mindview.util.*;
import static net.mindview.util.Print.*;

public class Ex7 {	
	@SuppressWarnings("unchecked")	
	public static void main(String[] args) {
		List<String> al = new ArrayList<String>(Countries.names(25));
		List<String> ll = new LinkedList<String>(Countries.names(25));
		print(al);
		print(ll);		
		Iterator alit = al.iterator();
		Iterator llit = ll.iterator();
		while(alit.hasNext()) {
			printnb(alit.next() + (alit.hasNext() ? ", " : ""));
		}
		print();
		while(llit.hasNext()) {
			printnb(llit.next() + (llit.hasNext() ? ", " : ""));
		}
		print();
		print();
		ListIterator allit = al.listIterator();
		ListIterator lllit = ll.listIterator();		
		while(lllit.hasNext()) {			
			allit.add((String)lllit.next());
			allit.next();
		}
		print(al);
		print();
		List<String> al2 = new ArrayList<String>(Countries.names(25));
		ListIterator allit2 = al2.listIterator();
		while(lllit.hasPrevious()) lllit.previous();
		while(allit2.hasNext()) allit2.next();
		while(lllit.hasNext()) {
			allit2.add((String)lllit.next());
			allit2.previous();
			allit2.previous();
		}
		print(al2);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -