通过for循环向ArrayList添加对象是否可行?
我想缩短代码!您有没有其他关于如何创建具有不同类和方法的单词测验的提示?
我有三个类,Main
驱动游戏,Quiz
构建游戏,以及一个包含所有单词的字典的类。
ArrayList<Sweng> Wordlist = new ArrayList<Sweng>();
Sweng s1 = new Sweng("bil", "car");
Sweng s2 = new Sweng("blå", "blue");
Sweng s3 = new Sweng("baka", "bake");
Sweng s4 = new Sweng("hoppa", "jump");
Sweng s5 = new Sweng("simma", "swim");
Sweng s6 = new Sweng("måne", "moon");
Sweng s7 = new Sweng("väg", "road");
Sweng s8 = new Sweng("snäll", "kind");
Sweng s9 = new Sweng("springa", "run");
Sweng s10 = new Sweng("hus", "house");
Wordlist.add(s1);
Wordlist.add(s2);
Wordlist.add(s3);
Wordlist.add(s4);
Wordlist.add(s5);
Wordlist.add(s6);
Wordlist.add(s7);
Wordlist.add(s8);
Wordlist.add(s9);
Wordlist.add(s10);
s#
变量:Wordlist.add(new Sweng("bil", "car")); ...
- EranList.of(new Sweng(...), new Sweng(...), ...)
。 - Joachim Sauer