Advertisement
Guest User

p2

a guest
Nov 25th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package lab08;
  2. import java.io.*;
  3. import java.util.LinkedList;
  4. import java.util.StringTokenizer;
  5. import java.util.TreeMap;
  6.  
  7. public class p2 {
  8.  
  9.     public static TreeMap<String,LinkedList> hash = new TreeMap<>();
  10.    
  11.     public static void main(String[] args) throws FileNotFoundException, IOException{
  12.         String path = "D:\\wow.txt";
  13.         LineNumberReader lnr = new LineNumberReader(new FileReader(path));
  14.         String linie = lnr.readLine();
  15.         while(linie!=null){
  16.             StringTokenizer st = new StringTokenizer(linie," .,;");
  17.             while(st.hasMoreTokens()){
  18.                 String cuvant = st.nextToken();
  19.                 if(hash.containsKey(cuvant)){
  20.                     LinkedList ll = hash.get(cuvant);
  21.                     ll.add(lnr.getLineNumber());
  22.                 }
  23.                 else{
  24.                     LinkedList ll=new LinkedList();
  25.                     ll.add(lnr.getLineNumber());
  26.                     hash.put(cuvant,ll);
  27.                 }
  28.             }
  29.             linie=lnr.readLine();
  30.         }
  31.        
  32.         System.out.println(hash.toString());
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement