Question: java I am using the code as a template and I am changing it to read from website instead of text file. that is already

java

I am using the code as a template and I am changing it to read from website instead of text file. that is already done on my version.

** I need to only grab a section of website that is in one of the DIV and ignore the rest. How can I do that?

import java.io.File; import java.io.FileNotFoundException; import java.util.*;

public class TextAnalyzer { public static void main(String[] args) throws FileNotFoundException { File file = new File("src/textFile.txt"); Scanner scan = new Scanner(file); Map map = new HashMap(); while (scan.hasNextLine()){

String val = scan.nextLine(); // reading line by line if(map.containsKey(val) == false) // if the string is not inserted in the map yet then insert by setting the frequency as 1 map.put(val,1); else // otherwise remove the entry from map and again insert by adding 1 in the frequency{ int count = (int)(map.get(val)); // finding the current frequency of the word map.remove(val); // removing the entry from the map map.put(val,count+1); } Set> set = map.entrySet(); // retrieving the map contents List> sortedList = new ArrayList>(set); // make an array list Collections.sort( sortedList, new Comparator>() // sorting the array list { public int compare( Map.Entry a, Map.Entry b ) // comparator function for sorting { return (b.getValue()).compareTo( a.getValue() ); // for descending order // return (a.getValue()).compareTo( b.getValue() ); // for ascending order } } ); // printing the list for(Map.Entry i:sortedList){ System.out.println(i.getKey()+" -> "+i.getValue()); }}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!