//Try java Comp tomorrow.txt import java.util.*; import java.util.Collections.*; import java.util.Comparator; import java.io.*; public class Comp { private static final Integer ONE = new Integer(1); public static void main(String args[]) { StreamTokenizer strt; List l = new ArrayList(); String fn = args[0]; try { strt = new StreamTokenizer(new BufferedReader(new InputStreamReader(new FileInputStream(args[0])))); strt.lowerCaseMode(true); //strt.wordChars('A','Z'); strt.wordChars('a','z'); while (strt.nextToken() != StreamTokenizer.TT_EOF) { if (strt.ttype == StreamTokenizer.TT_WORD) { l.add(strt.sval); } } } catch (FileNotFoundException e){ System.out.println("Fichier " + fn + " pas trouve"); System.exit(0); } catch (IOException e) { System.out.println("IO Exception"); System.exit(0); } System.out.println("Default:\n" + l); Collections.sort(l); System.out.println("Default:\n" + l); Collections.sort(l,new Comparator() { public int compare(Object o1, Object o2) { return (((String)o2).length() - ((String)o1).length()); } }); System.out.println("New order:\n:" + l); } }