List <Person> pers = new ArrayList<Person>();
pers.add(new Women("something1"));
pers.add(new Women("something2"));
pers.add(new Men("something1"));
pers.add(new Men("something2"));
System.out.println(pers); // prints everything
The classes Women and Men extend Person. After I store the data in my list how do I print only the Women or only the Men? Also how do I access attributes from the Women and Men?
With 2 lists works fine but I'm having trouble when I only have to use one list.
instanceofoperator, but that usually means that your design is flawed. Why do you want to create only one list of peers? What is wrong with solution using two separate lists?