Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

3. Raster images for screen projects need to be 72 dpi to scale.

Answered: 1 week ago