hashmap - How to get the size of String java.util.Map.Entry.getKey() in java? -


i tried options not required output.

the question how size of m.getkey()

i tried m.getkey().length ,m.getkey().size not find.

system.out.print("\n duplicate words: "); for(map.entry<string, integer> m:  map.entryset()){ if(m.getvalue()>tostringarray.length-1) ); system.out.print(m.getkey() + " "); } 

the output

( hi output)

the output needed

(5) //hi output total count 5

suggestions welcomed.

i beginner java

here full code

import java.io.file; import java.io.fileinputstream; import java.io.file; import java.io.filenotfoundexception; import java.io.ioexception; import java.util.hashmap; import java.util.map; import java.util.scanner; import org.apache.commons.io.ioutils;   public class testduplicatewordnew { public static void main(string[] args) throws exception {  /* reading text content file    */  fileinputstream fistargetfile = new fileinputstream(new file("e:\\testfolder\\மிரளச் செய்யும் மிலரபாவின் கதை!  isha tamil blog 15.txt"));      string targetfilestr = ioutils.tostring(fistargetfile, "utf-8");   string []tostringarray = targetfilestr.split(" ");    hashmap<string , integer> map = analyzewords("analyzing contents ", tostringarray);     system.out.print("\nduplicate words: ");  for(map.entry<string, integer> m:  map.entryset()){  if(m.getvalue()>tostringarray.length-1) // system.out.print(m.getkey() + "-" + m.getvalue()/(tostringarray.length-1) + " ");   system.out.print(m.getkey()+ " ");  // system.out.println(map.keyset().size()); // system.out.println(m.getvalue());   }  system.out.println("\n");  }   private static hashmap<string, integer> analyzewords(string command, string []tostringarray ){ system.out.println(command);    hashmap<string, integer> unik = new hashmap<string, integer>();    int =0; while(i<tostringarray.length){ unik.put(tostringarray[i++], 0);}   for(i = 0; i< tostringarray.length; i++){     for(int j = 0; j< tostringarray.length; j++ ){  if( (tostringarray[i] != tostringarray[j]) && (i != j))   unik.put(tostringarray[i],(int)unik.get(tostringarray[i]) +1);  }  }// oef outter loop    return unik;  }// eof analyzewords method   /* method read file content.   * returns contents of text file string */  private static string filenamereader(string filename) throws filenotfoundexception{ system.out.println("\nreading " +filename+ " file"); string generatestring = ""; try{     file file = new file(filename);  scanner scanner = new scanner(file);   generatestring = scanner.nextline();  while (scanner.hasnextline()) {       generatestring = generatestring + "\n" + scanner.nextline();  }scanner.close();  system.out.println("\ninitial content");  system.out.println(generatestring); }catch(ioexception e){  system.out.println("\nerror occured while reading file...");  } return generatestring;  }// eof filenamereader method } 

you try bellow count words in key:

string keys = ""; for(map.entry<string, integer> m:  map.entryset()){  if(m.getvalue()>tostringarray.length-1)     keys = keys + " " + m.getkey(); } system.out.print(keys.trim().split("\\s+").length); 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -