Java - output user input in case-insensitive sorted order?

So I'm new to java and I am currently learning about reading textfiles and input and such. I'm trying to write a program that reads the input one line at a time. When the user is done, it should output all the lines in case-insensitive sorted order. Right now it outputs my lines in alphabetical order, but... show more So I'm new to java and I am currently learning about reading textfiles and input and such. I'm trying to write a program that reads the input one line at a time. When the user is done, it should output all the lines in case-insensitive sorted order.

Right now it outputs my lines in alphabetical order, but I can't figure out a way to make it in case-insensitive order. I was wondering if someone could help?

As a side note, do you have any suggestions to make my code more efficient and shorter?

public static void doIt(BufferedReader r, PrintWriter w) throws IOException {
ArrayList<String> myList=new ArrayList<String>();



Set<String> s = new HashSet<String>();
String line;
while (true) {
line = r.readLine();
if (line != null) {
s.add(line);
} else {
break;
}

}
List<String> list = new ArrayList<String>(s);
Collections.sort(list);
for (String string : list) {
w.println(string);
}
}
1 answer 1