tag:blogger.com,1999:blog-694855878384792308.post763193944528561753..comments2024-03-15T23:19:22.318-07:00Comments on Java67: How to Find Highest Repeating Word from a File in Java [Word Count Solution]javin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-694855878384792308.post-84783415727987197112017-09-09T05:15:16.991-07:002017-09-09T05:15:16.991-07:00If the file is too large which would result in jav...If the file is too large which would result in java.lang.OutOfMemoryError, how do you make sure you process only part of the file that would not result in the memory error. In the article it was mentioned as read only 20% process it and move on to next part until you finish processing the entire file. How do you make sure you read only 20% and next time continue from the next 20%. Thanks in AdvanceSIVA krishnahttps://www.blogger.com/profile/05064377343986331213noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-32418046345717228422017-04-20T02:36:02.623-07:002017-04-20T02:36:02.623-07:00I think you forgot this:
line += line + "...I think you forgot this:<br /> line += line + "\n";<br />before<br /> line = line.toLowerCase();<br /><br />If the text file has many empty lines, you'll got this output:<br />=> specific numberAnonymoushttps://www.blogger.com/profile/01834713905311771412noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-83209431312597030162017-01-27T21:43:17.067-08:002017-01-27T21:43:17.067-08:00Why sort the list at all? The original question as...Why sort the list at all? The original question asks to "find highest repeating word", you can just navigate the map and find the highest value. This way you are still at O(n) rather than O(n logn) once you resort to sorting.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-17436598975194770802016-12-08T09:08:05.215-08:002016-12-08T09:08:05.215-08:00Let's see this chain of object creation, file ...Let's see this chain of object creation, file name -> FileInputStream -> DataInputStream -> InputStreamReader -> BufferReader, then finally you can stream content of this file, no wonder Java is such resource hogAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-5216065597635207762016-05-13T21:24:31.337-07:002016-05-13T21:24:31.337-07:00How to print the occurances of the word bases on t...How to print the occurances of the word bases on the line number , i want to print 5 most occurances of the word.testhttps://www.blogger.com/profile/08888766707162970839noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-69100966958880678742016-05-13T21:12:29.457-07:002016-05-13T21:12:29.457-07:00How to print the line number in which maximum occu...How to print the line number in which maximum occurances occured , i wanted to show top 5 occurances of the word with the line numbertesthttps://www.blogger.com/profile/08888766707162970839noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-77824559913639488942015-10-04T22:27:13.574-07:002015-10-04T22:27:13.574-07:00How does the second point solve your memory proble...How does the second point solve your memory problem. Out of memory can occur, if the line is to long or the word map gets too big. For a too long line you need a custom read method. For the a big map you need some external storage solution. If you only store the maximum repeated words (like the top 10, did I understand this correctly?) , you may get wrong results.Anonymoushttps://www.blogger.com/profile/10273624628253736736noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-67433368508877444202015-10-04T22:16:18.309-07:002015-10-04T22:16:18.309-07:00Nice solution showing the power of streams, but us...Nice solution showing the power of streams, but uses temporarily more memory. Anonymoushttps://www.blogger.com/profile/10273624628253736736noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-63727297832011024402015-10-04T22:08:43.430-07:002015-10-04T22:08:43.430-07:00For an interview, I would also expect that the sou...For an interview, I would also expect that the source follows the "single level of abstraction" principle ( the buildWordMap function).Anonymoushttps://www.blogger.com/profile/10273624628253736736noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-65457281255701303872015-10-02T05:22:02.859-07:002015-10-02T05:22:02.859-07:00Nice smile emoticon On java 8 it has done with 4 c...Nice smile emoticon On java 8 it has done with 4 code line :<br /><br />String data = String.join("", Files.readAllLines(Paths.get("D:\\lab.txt")));<br /><br />Arrays.asList(data.split(("\\s+"))).stream().collect(Collectors.groupingBy(str->str)).forEach((text,list)->{<br />System.out.println(String.format("Word: %s - Occur: %d",text,list.size()));});Anonymousnoreply@blogger.com