containercomparison15.java
来自「JAVA编程思想第四版英文原版习题答案. pdf原版的」· Java 代码 · 共 30 行
JAVA
30 行
// arrays/ContainerComparison15.java
// TIJ4 Chapter Arrays, Exercise 15, page 775
// Modify ContainerComparison.java by creating a Generator for
// BerylliumSphere, and change main() to use that Generator
// with Generated.array().
import net.mindview.util.*;
import java.util.*;
import static net.mindview.util.Print.*;
class BerylliumSphereGenerator implements Generator<BerylliumSphere> {
public BerylliumSphere next() {
return new BerylliumSphere();
}
}
public class ContainerComparison15 {
public static void main(String[] args) {
BerylliumSphere[] spheres = new BerylliumSphere[5];
BerylliumSphereGenerator bsg = new BerylliumSphereGenerator();
Generated.array(spheres, bsg);
print(Arrays.toString(spheres));
print(spheres[4]);
List<BerylliumSphere> sphereList =
new ArrayList<BerylliumSphere>();
for(int i = 0; i < 5; i++)
sphereList.add(bsg.next());
print(sphereList);
print(sphereList.get(4));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?