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

📄 ex7.java

📁 JAVA编程思想第四版英文原版习题答案. pdf原版的
💻 JAVA
字号:
// holding/Ex7.java
// TIJ4 Chapter Holding, Exercise 7, page 406
/* Create a class, then make an initialized array of objects of your class
* Fill a List from your array. Create a subset of your List by using 
* subList(), then remove this subset from your List.
*/
import java.util.*;
import static net.mindview.util.Print.*;

class Tester {
	public static int counter = 0;
	private int id = counter++;
	public String toString() { return String.valueOf(id); }	
}

public class Ex7 {
	public static void main(String[] args) {		
		Tester[] t = new Tester[10];
		for(int i = 0; i < t.length; i++)
			t[i] = new Tester();
		List<Tester> lt = new ArrayList<Tester>();
		for(Tester x : t) lt.add(x);
		print("list of Tester: " + lt);
		List<Tester> sub = lt.subList(2, 6);
		print("subList: " + sub);
		// produces run time ConcurrentModificationException:
		// lt.removeAll(sub);
		// so, first make copy, remove sub, re-assign lt:
		List<Tester> copy = new ArrayList<Tester>(lt);
		copy.removeAll(sub);
		print("copy: " + copy);
		lt = copy;
		print("list of Tester: " + lt);
	}
}

⌨️ 快捷键说明

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