I have an ArrayList of MyClass and I need to extract multiple lists from it according to the repetition of a property of the class.
MyClass:
public class MyClass{
private int ID;
private String Name;
private String Position;
public MyClass(int ID, String name, String position){
this.ID = ID;
Name = name;
Position = position;
}
}
Example:
In my ArrayList I have 5 objects:
ID = 0, Name = "Name 0", Position = "G1.1";
ID = 1, Name = "Name 1", Position = "G2.1";
ID = 2, Name = "Name 2", Position = "G1.1";
ID = 3, Name = "Name 3", Position = "G1.1";
ID = 4, Name = "Name 4", Position = "G2.1";
From this list I'll create 2 ArrayLists:
ArrayList 1 (Where Position = "G1.1")
ID = 0, Name = "Name 0", Position = "G1.1";
ID = 2, Name = "Name 2", Position = "G1.1";
ID = 3, Name = "Name 3", Position = "G1.1";
ArrayList 2 (Where Position = "G2.1")
ID = 1, Name = "Name 1", Position = "G2.1";
ID = 4, Name = "Name 4", Position = "G2.1";
The main list is created dynamically, so I don't know what will be the positions I will need to create to get the items.