I am making an ArrayList with 3 different types of groups. The objective I am trying to achieve is:
- It ensures randomization (Collections.shuffle) (Done)
- Using a sublist, I can pick a specific number of elements in the ArrayList (Done)
- To prevent duplication appearing in the other groups when running the program, I implement a HashSet (Not done)
I can't seem to combine #2 and #3. Maybe I'm just not understanding how HashSets are done yet. Here is my code:
class code {
public static void main(String[] args) {
//This is creating the ArrayList with everything added
List one = new ArrayList();
List two = new ArrayList();
List three = new ArrayList();
one.add("United States");
one.add("United Kingdom");
one.add("Italy");
one.add("France");
one.add("Russia");
one.add("Japan");
one.add("China");
one.add("Mexico");
two.add("Philippines");
two.add("Austria");
two.add("Canada");
two.add("Sweden");
two.add("Iceland");
two.add("India");
two.add("Australia");
two.add("Deutschland");
three.add("Norway");
three.add("Kosovo");
three.add("North Korea");
three.add("Sudan");
three.add("United Arab Emirates");
three.add("Bahrain");
three.add("Haiti");
//Formatting purposes
System.out.println("Country Categories: ");
System.out.println("#1 Countries = " + one);
System.out.println("#2 Countries = " + two);
System.out.println("#3 Countries = " + three);
System.out.println("\n");
//Randomization code. I use this method so it's shuffled the same way.
long seed = System.nanoTime();
Collections.shuffle(one, new Random(seed));
Collections.shuffle(two, new Random(seed));
Collections.shuffle(three, new Random(seed));
System.out.println("Group #1");
List largelist = one.subList(1,4);
System.out.println(largelist);
List mediumlist = two.subList(1,4);
System.out.println(mediumlist);
List smalllist = three.subList(1,3);
System.out.println(smalllist);
/*System.out.println("Group #2");
List largerlist = one.subList(1,4);
System.out.println(largerlist);
List mediumrlist = two.subList(1,4);
System.out.println(mediumrlist);
List smallrlist = three.subList(1,3);
System.out.println(smallrlist);
System.out.println("Group #3");
List largerrlist = one.subList(1,3);
System.out.println(largerrlist);
List mediumrrlist = two.subList(1,3);
System.out.println(mediumrrlist);
List smallrrlist = three.subList(1,3);
System.out.println(smallrrlist);*/
}
} //I only put one group because of issue I am having
I didn't implement my HashSet in this because it looked embarrassing but here it is:
System.out.println("Group #1");
Set largeset = new HashSet(one);
for (Object wow : one) {
List largelist = one.subList(1,4);
System.out.println(largelist);
System.out.println(wow);
My intended output I wanted is something like this:
Group #1 //Week 1
[United Kingdom, Italy, Russia]
[Philippines, Canada, Iceland]
[Bahrain, Sudan]
Group #2
[France, United States, Japan]
[Sweden, India, Austria]
[Kosovo, North Korea]
Group #3
[Mexico, China]
[Australia, Deutschland]
[United Arab Emirates, Norway]
Randomization to Randomize, SubList to choose specific arrays and print them, and a HashSet to prevent duplication.
Keep in mind this is just for 1 week, now I must find a way for it to recur so that every country meets up at least once in 5 weeks -_- Help/Advice/Examples are appreciated, but figuring this out is my main goal.