Nonsense not much to say that directly on the code
Copy Code code as follows:
Package com.b;
Import java.util.ArrayList;
Array traversal deletion, adding
public class Core2 {
private String name;
private int num;
private String color;
Public Core2 () {
}
Public Core2 (String a, int B, string c) {
name = A;
num = b;
color = c;
}
Public String GetName () {
return name;
}
Public String GetColor () {
return color;
}
public int Getnum () {
return num;
}
public static void Main (string[] args) {
Core2 C = new Core2 ("Little Red", 13, "red");//Create 3 instances
Core2 C2 = new Core2 ("Xiaoming", 12, "yellow");/= Object
Core2 C3 = New Core2 ("Cockroach", 123, "Blue");
Core2 C4 = new Core2 ("Small Li", 23, "white");
Core2 c5 = new Core2 ("Little Love", 4, "Blue");
Core2 C6 = new Core2 ("Small North", 2, "brave");
ArrayList AA = new ArrayList ();//Collection Container
Aa.add (c);
Aa.add (C2);
Aa.add (C3);
Aa.add (C4);
Aa.remove (1);
Aa.add (2, C5);
Aa.add (1, C6);
Aa.remove (C4);
SYSTEM.OUT.PRINTLN ("size is:" + aa.size ());
for (int i = 0; i < aa.size (); i++) {
Core2 m = (Core2) aa.get (i)//ArrayList traversal and increase
System.out.println ("No." + (i + 1) + "Student Name:" + m.getname () + ", School number is:"
+ m.getnum () + ", Color is:" + m.getcolor ());
}
}
}
Size is: 5
1th student Name: Xiao Hong, school number is: 13, the color is: red
2nd student Name: Xiao Bei, school number is: 2, the color is: brave
3rd student Name: Xiao Ming, school number is: 12, the color is: yellow
4th Student Name: Little Love, School number is: 4, the color is: Blue
5th student Name: Xiao Qiang, school number is: 123, the color is: Blue