[![enter image description here](https://i.stack.imgur.com/kmnGt.png)](https://i.stack.imgur.com/kmnGt.png)I am designing a group generator that takes in preferences such as “mix gender”, “mix nationality”... I am putting a list of student names, followed by nationality and gene set, in an arraylist. What is the easiest way to generate groups, based on user input, that each group consists of people from different nationalities, or balanced gender.

```java
 public ArrayList<String> readEachWord(String className)
    {
        ArrayList<String> readword = new ArrayList<String>();
        Scanner sc2 = null;
        try {
        sc2 = new Scanner(new File(className + ".txt"));
    } catch (FileNotFoundException e) {

        System.out.println("error, didnt find file");
        e.printStackTrace();  
    }
    while (sc2.hasNextLine()) {
            Scanner s2 = new Scanner(sc2.nextLine());
        while (s2.hasNext()) {
            String s = s2.next();
            readword.add(s);
        }
    }
    return readword;

    }

```

I am using this to read a text file, and on each line, I have each student's name nationality and gender. I put them into an ArrayList and am right now trying to figure out how to evenly distribute them based on the user-desired group numbers.

I am using a txt file to store all the information since this group generator is customized for my school.