I am making a program that sets up an experiment for me and I want to alphabetize the subjects (or people) that i input. I have an arraylist of type subjects and i want to alphabetize them by their names.
import java.util.Random;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
public class Experiment
{
public Random number;
public ArrayList<String> allSubject;
public ArrayList<Subject> allSubjects,alphaSubjects;
public ArrayList<Group> experiment;
public Integer value;
public HashMap<Integer,Subject> matched;
private ArrayList<Integer> numbers;
/**
 * Make a new Experiment.  Then use method addSubject to add
 * Subjects to your experiment.  Then call the assignGroups
 * method to assign Subjects to each group.
 */
public Experiment()
{
    number = new Random();
    numbers = new ArrayList<Integer>();
    experiment = new ArrayList<Group>();
    matched = new HashMap<Integer,Subject>();
    allSubjects = new ArrayList<Subject>(); 
    allSubject = new ArrayList<String>();
    alphaSubjects = new ArrayList<Subject>();
}
/**
 * Alphabetizes the list of Subjects based on their
 * name input by the user.  As of right now, this method
 * is case sensitive meaning Strings starting with 
 * capitals will be listed before those without capitals.
 */
private void alphabetize()
{
           Collections.sort(allSubject);
        //compare the String arraylist to the subject arraylist to reset the subject arraylist indeces in alphabetical order.
       for(int i =0;i<allSubject.size();i++)
       {
        String theName = allSubject.get(i);
         for(Subject subject:allSubjects)
        {
          if(subject.getName().toLowerCase().contains(theName))
         {
            alphaSubjects.add(new Subject(subject.getName(),subject.getDescription()));
         }
        }
     }
}
/**
 * Adds a new Subject to the experiment.
 */
public void addSubject(String name, String description)
{
    allSubjects.add(new Subject(name,description));
    allSubject.add((name.toLowerCase()));
}
So instead of having to add a subject to an arraylist then having to strip the name from that subject and add it to a completely different arraylist, is there a way to alphabetize by the name of the subject.
oh and here is the class: subject.
public class Subject
{
public final String name;
public final String description;
public Subject(String name, String description)
{
    this.name = name;
    this.description = description;
}
public Subject(int aNumber)
{
    name = "Subject" + aNumber;
    aNumber++;
    description = "default";
}
public String getName()
{
    return name;
}
public String getDescription()
{
    return description;
}
}
 
     
     
    