vector_ever
Mitglied
Code:
public class Employee{
private int id;
private String name;
private String address;
private double salary;
//setter & getter
}
Code:
public class test{
ArrayList check= coll ();
CheckCollection(check);
public static ArrayList coll (){
ArrayList list = new ArrayList();
Set set = new HashSet();
Employee ts1 = new Employee (10, "Jad", "L.A", 200.0);
Employee ts2 = new Employee (11, "Amal", "Berlin", 600.0);
Employee ts3 = new Employee (12, "Jasmin", "London", 250.0);
Employee ts4 = new Employee (10, "sam", "Paris", 200.0);
Employee ts5 = new Employee (14, "Adam", "NY", 210.0);
set.add(ts1);
set.add(ts2);
set.add(ts3);
set.add(ts4);
set.add(ts5);
//now convet the Set to List
list.add(set);
return list;
}
public static void CheckCollection(ArrayList data) {
ArrayList xxx= null;
for (int i = 0; i < data.size(); i++) {
xxx = (ArrayList)data.get(i);
}
}
Bei der Ausführung kriege ich Fehlermeldung:
HTML:
java.lang.ClassCastException: java.util.HashSet cannot be cast to java.util.ArrayList
Ich dachte list.add(set); hat die Elemente drin von Set zu List Konvertiert !!