/* Copyright 2005 Daniel Cer (daniel.cer@cs.colorado.edu) This work is licensed under the Creative Commons Attribution-NonCommercial- ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA. */ import java.io.FileReader; import java.io.BufferedReader; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; public class LibrarySort { public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println( "Usage:\n\tjava LibrarySort (file with numbers to sort)"); System.exit(-1); } ArrayList items = new ArrayList(); BufferedReader breader = new BufferedReader(new FileReader(args[0])); // read in the items for (String inLine; (inLine = breader.readLine()) != null; ) items.add(Float.valueOf(inLine)); // sort them Collections.sort(items); // display the results for (Iterator iter = items.iterator(); iter.hasNext(); ) { Float f = iter.next(); System.out.println(f); } } }