1 Reply Latest reply: Jan 18, 2013 1:39 AM by PhHein RSS

    wordsorter in descending order(every single word) from any input file

    985610
      import java.awt.List;
      import java.io.File;
      import java.io.IOException;
      import java.util.ArrayList;
      import java.util.Collections;
      import java.util.Map;
      import java.util.Scanner;
      import java.util.StringTokenizer;
      import java.util.TreeMap;

      //this is as far as i have reached

      public class Wordsorter {

           ArrayList<String> wordList;

      public Wordsorter(String fileName) throws IOException {
           wordList = new ArrayList<String>();
      //should scan any file
      Scanner fileScanner = new Scanner( new File( fileName ) );

      while( fileScanner.hasNext() )
      {
           while (fileScanner.hasNextLine()) {
                          String line = fileScanner.nextLine();
                          // breaking files to small words
                          StringTokenizer wordList = new StringTokenizer(line, "0123456789 ~!@#$%^&*()_+-={}[]|\\:\";'<>?,./'");
                          
                     }
      }
           }
           
      public void sort()
      {
      // i dont know but i created a map to count words to order it in descending order
           Map<String,Integer> sorter = new TreeMap<String,Integer>();
           
      int j;
      j = wordList.size();
      sorter.put(wordList, j);
      Collections.sort(wordList);
      // i need help to put it in descending order
      }
           
      public static void main( String[] args ) throws IOException
      {
      if( args.length == 0 )
      {
      System.out.println( "Usage: java WordSorter wordFile" );
      return;
      }

      Wordsorter word = new Wordsorter( args[0] );
      word.sort();
      }
           
      }
      //this is as far i have reached

      Edited by: 982607 on Jan 17, 2013 10:56 PM