+ 1

Why Does my entries not work with .hasNext()?

Im doing this code with HeapSort and i want to make it read a txt file count and order alphabetical all the words, but i get an error on the while(entry.hasNext()) that i cant solve, anyone knows why this happens?? public static void main(String[] args) throws FileNotFoundException, IOException { String cami="C:\\Users\\Carlos\\Documents\\NetBeansProjects\\Practica3_Text\\src\\"; FileReader fr = new FileReader(cami+"TM.txt"); BufferedReader br = new BufferedReader(fr); int n; int mida=0; String s = br.readLine(); // reads a single line Map<String,Integer> Map = new HashMap<String, Integer>(); while(s!=null) { String[] t=s.split("\\s"); // split by spaces and generates an array of Strings -words- for(int i=0;i<t.length;i++){ Iterator<Map.Entry<String, Integer>> entries = Map.entrySet().iterator(); if(Map.containsKey(t[i])){ for(Map.Entry<String, Integer> entry : Map.entrySet()){ System.out.println("Clave: "+ entry.getKey()+"Valor: "+entry.getValue()); if(t[i].equals(entry.getKey())){ Map.put(entry.getKey(),entry.getValue()+1); }} }else{ Map.put(t[i],1); } } s = br.readLine(); } HeapSort<String> hs = new HeapSort<>(mida); br.close(); while(entry.hasNext()){ Map.Entry<String, Integer> entry = entry.next(); hs.Insert(entry.getKey()); //System.out.println("clave=" + hs.Lesser() + ", valor=" + Map.get(hs.Lesser())); } while(!hs.Empty()){

4th Jun 2017, 9:25 AM
carlos nuñez
carlos nuñez - avatar
4 Respostas
+ 1
Java?
4th Jun 2017, 11:39 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
Java?
4th Jun 2017, 11:39 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
0
yeah it's java
4th Jun 2017, 12:16 PM
carlos nuñez
carlos nuñez - avatar
0
hasnext() function is used for checking if there are any more input from the user or not . for example: Scanner sc=new Scanner(System.in); int [] are= new are[100]; l=0; while(sc.hasnext()) { arr[I]=sc.nextInt(); l++; } I doubt if it can be used with string or not.
4th Jun 2017, 1:18 PM
Navin