【发布时间】:2018-04-28 16:07:16
【问题描述】:
我需要 #3 和 #5 方面的帮助。
-
创建一个集合并用 1 到 15(含)之间的 20 个随机数填充它
List<Integer> list1 = new ArrayList<Integer>(Arrays.asList( rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1), rand.nextInt(15 + 1) )); -
打印数字
System.out.println(list1); -
为 Random 类的构造函数提供值为 13 的种子。
- 播种 ctor 是什么意思?
-
将集合序列化为名为 Numbers.ser 的文件
try (ObjectOutputStream serialize = new ObjectOutputStream(new FileOutputStream("src/serialize/Numbers.ser"))) { serialize.writeObject(list1); } catch (IOException e) { e.printStackTrace(); } -
将文件反序列化为一个名为 numberFromFile 的新集合。删除所有重复的数字
- 这是我对如何反序列化感到困惑的地方。解释是什么?
【问题讨论】:
标签: java serialization deserialization