填充數組..創建和我開發的應用程序最簡單的方法
class Wheel {
private int size;
Wheel(int s) {
size = s;
}
void spin() {
System.out.print(size + " inch wheel spinning, ");
}
}
public class Bicycle {
public static void main(String[] args) {
Wheel[] wa = { new Wheel(15), new Wheel(17) };
for (Wheel w : wa)
w.spin();
}
}
但是請提醒,我們怎麼能在更簡單的術語表達Wheel[] wa = { new Wheel(15), new Wheel(17) };
。
請務必查看Java Collections API。集合優於數組,因爲集合(Set,List等)更容易處理。 – rob 2012-04-29 06:55:04