This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
public class Driver4 {//GOAL: count frequency of words held in a REMOTE text file// Reading “Health & Science” news from NPR-RSS website
public static void main(String[] args) {
Map<String, Integer> map = new TreeMap<>();
try {
URL myLink = new URL("http://www.npr.org/rss/rss.php?id=1007");
Scanner scanner = new Scanner(myLink.openStream());
while (scanner.hasNext() ){String line = scanner.nextLine();System.out.println( line );// using \\b word-boundary regular expressionString[] tokens = line.split("\\b"); for(int i=0; i<tokens.length; i++){
String key = tokens[i];
if( map.containsKey( key )){Integer value = map.get(key);map.put(key, value+1);
} else {map.put(key, 1);
}
}
}
//all done!, now pretty printing for( String key: map.keySet() ){
<?xml version="1.0" encoding="UTF-8"?><rss xmlns:npr="http://www.npr.org/rss/" xmlns:nprml="http://api.npr.org/nprml" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"> <channel> <title>Science : NPR</title> <link>http://www.npr.org/templates/story/story.php?storyId=1007</link> <description>The latest health and science news. Updates on medicine, healthy living, nutrition, drugs, diet, and advances in science and technology. Subscribe to the Health & Science podcast.</description> <language>en</language> <copyright>Copyright 2015 NPR - For Personal Use Only</copyright> <generator>NPR API RSS Generator 0.94</generator> <lastBuildDate>Tue, 09 Jun 2015 12:19:00 -0400</lastBuildDate> <image> <url>http://media.npr.org/images/podcasts/primary/npr_generic_image_300.jpg?s=200</url> <title>Science</title> <link>http://www.npr.org/templates/story/story.php?storyId=1007</link> </image> <item> <title>To Beat Insomnia, Try Therapy For The Underlying Cause Instead Of Pills</title> <description>A review of the medical evidence finds that therapy can break the cycle of chronic sleeplessness by addressing the anxieties that cause many people to stay awake.</description> <pubDate>Tue, 09 Jun 2015 12:19:00 -0400</pubDate> <link>http://www.npr.org/sections/health-shots/2015/06/09/412938919/to-beat-insomnia-try-therapy-for-underlying-cause-instead-of-pills?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/sections/health-shots/2015/06/09/412938919/to-beat-insomnia-try-therapy-for-underlying-cause-instead-of-pills?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>A review of the medical evidence finds that therapy can break the cycle of chronic sleeplessness by addressing the anxieties that cause many people to stay awake.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=412938919">» E-Mail This</a></p>]]></content:encoded> <dc:creator>Maanvi Singh</dc:creator> </item> <item> <title>Smoking Pot Interferes With Math Skills, Study Finds</title> <description>Researchers studying the effects of marijuana faced an obstacle: they couldn't create an exact control group. But a change in drug laws in the Netherlands offered a perfect laboratory.</description> <pubDate>Tue, 09 Jun 2015 05:04:00 -0400</pubDate> <link>http://www.npr.org/2015/06/09/413069509/smoking-pot-interferes-with-math-skills-study-found?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/2015/06/09/413069509/smoking-pot-interferes-with-math-skills-study-found?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>Researchers studying the effects of marijuana faced an obstacle: they couldn't create an exact control group. But a change in drug laws in the Netherlands offered a perfect laboratory.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=413069509">» E-Mail This</a></p>]]></content:encoded> <dc:creator>Shankar Vedantam</dc:creator> </item> <item> <title>As MERS Outbreak Surges, Genetic Tests Show Virus Hasn't Mutated</title> <description>So the spread of the Middle East respiratory syndrome in South Korea is probably due to other factors, such as a delayed response to the outbreak and poor infection control at hospitals.</description> <pubDate>Mon, 08 Jun 2015 20:38:00 -0400</pubDate> <link>http://www.npr.org/sections/goatsandsoda/2015/06/08/412913709/as-mers-outbreak-surges-genetic-tests-show-virus-hasnt-mutated?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/sections/goatsandsoda/2015/06/08/412913709/as-mers-outbreak-surges-genetic-tests-show-virus-hasnt-mutated?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>So the spread of the Middle East respiratory syndrome in South Korea is probably due to other factors, such as a delayed response to the outbreak and poor infection control at hospitals.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=412913709">» E-Mail This</a></p>]]></content:encoded> <dc:creator>Michaeleen Doucleff</dc:creator> </item>
<item> <title>Solar Sail Unfurls In Space</title> <description>A nonprofit has successfully tested technology that could one day be used to explore the solar system on a budget.</description> <pubDate>Mon, 08 Jun 2015 17:14:00 -0400</pubDate> <link>http://www.npr.org/sections/thetwo-way/2015/06/08/412939540/solar-sail-unfurls-in-space?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/sections/thetwo-way/2015/06/08/412939540/solar-sail-unfurls-in-space?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>A nonprofit has successfully tested technology that could one day be used to explore the solar system on a budget.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=412939540">» E-Mail This</a></p>]]></content:encoded> <dc:creator>Geoff Brumfiel</dc:creator> </item> <item> <title>Online Health Searches Aren't Always Confidential </title> <description>Searching a medical issue on the Internet seems harmless enough, but one researcher found that online medical searches may be seen by hidden parties, and the data even sold for profit.</description> <pubDate>Mon, 08 Jun 2015 16:41:00 -0400</pubDate> <link>http://www.npr.org/sections/alltechconsidered/2015/06/08/412893469/online-health-searches-arent-always-confidential?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/sections/alltechconsidered/2015/06/08/412893469/online-health-searches-arent-always-confidential?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>Searching a medical issue on the Internet seems harmless enough, but one researcher found that online medical searches may be seen by hidden parties, and the data even sold for profit.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=412893469">» E-Mail This</a></p>]]></content:encoded> <dc:creator>NPR Staff</dc:creator> </item> <item> <title>Pitmasters Embrace New Barbecue Truth: Rested Meat Is Sublime</title> <description>How to rest a pork shoulder, a beef brisket or rack of ribs to keep it moist hours after it comes off the pit? Restaurants now use warming units, but DIY home warmers are just as good.</description> <pubDate>Mon, 08 Jun 2015 16:37:00 -0400</pubDate> <link>http://www.npr.org/sections/thesalt/2015/06/08/411778404/pitmasters-embrace-new-barbecue-truth-rested-meat-is-sublime?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/sections/thesalt/2015/06/08/411778404/pitmasters-embrace-new-barbecue-truth-rested-meat-is-sublime?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>How to rest a pork shoulder, a beef brisket or rack of ribs to keep it moist hours after it comes off the pit? Restaurants now use warming units, but DIY home warmers are just as good.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=411778404">» E-Mail This</a></p>]]></content:encoded> <dc:creator>Jim Shahin</dc:creator> </item> <item> <title>NASA's 'Flying Saucer' Test For Advanced Parachute Appears To Fail</title> <description>A giant balloon carried the Low-Density Supersonic Decelerator to an altitude of 120,000 feet to test the device, which could be used on Mars missions. It seemed to deploy correctly, then tear apart.</description> <pubDate>Mon, 08 Jun 2015 15:34:00 -0400</pubDate> <link>http://www.npr.org/sections/thetwo-way/2015/06/08/412933683/nasa-sends-flying-saucer-on-its-way-to-120-000-feet-above-earth?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/sections/thetwo-way/2015/06/08/412933683/nasa-sends-flying-saucer-on-its-way-to-120-000-feet-above-earth?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>A giant balloon carried the Low-Density Supersonic Decelerator to an altitude of 120,000 feet to test the device, which could be used on Mars missions. It seemed to deploy correctly, then tear apart.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=412933683">» E-Mail This</a></p>]]></content:encoded> <dc:creator>Bill Chappell</dc:creator> </item> <item> <title>Do Creativity And Schizophrenia Share A Small Genetic Link? Maybe</title>
<description>The notion goes back to the ancients — that minds given to flights of fancy are on the healthy side of a spectrum that includes what we today call psychosis. An Icelandic gene study offers new clues.</description> <pubDate>Mon, 08 Jun 2015 11:17:00 -0400</pubDate> <link>http://www.npr.org/sections/health-shots/2015/06/08/412314685/do-creativity-and-schizophrenia-share-a-small-genetic-link-maybe?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/sections/health-shots/2015/06/08/412314685/do-creativity-and-schizophrenia-share-a-small-genetic-link-maybe?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>The notion goes back to the ancients — that minds given to flights of fancy are on the healthy side of a spectrum that includes what we today call psychosis. An Icelandic gene study offers new clues.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=412314685">» E-Mail This</a></p>]]></content:encoded> <dc:creator>Angus Chen</dc:creator> </item> <item> <title>Drought-Friendly Recipes Kick Up The Flavor — And Cut Back On Water</title> <description>An LA chef and his partner are cooking up recipes using ingredients that require less water to grow and cook with. They want to get us thinking about the resources that go into growing our food.</description> <pubDate>Mon, 08 Jun 2015 09:46:00 -0400</pubDate> <link>http://www.npr.org/sections/thesalt/2015/06/08/412037546/drought-friendly-recipes-kick-up-the-flavor-and-cut-back-on-water?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/sections/thesalt/2015/06/08/412037546/drought-friendly-recipes-kick-up-the-flavor-and-cut-back-on-water?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>An LA chef and his partner are cooking up recipes using ingredients that require less water to grow and cook with. They want to get us thinking about the resources that go into growing our food.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=412037546">» E-Mail This</a></p>]]></content:encoded> <dc:creator>Ezra David Romero</dc:creator> </item> <item> <title>Lost Posture: Why Some Indigenous Cultures May Not Have Back Pain</title> <description>There are a few populations in the world where back pain hardly exists. One woman thinks she has figured out why, and she's sharing their secrets. Have Americans forgotten how to stand properly?</description> <pubDate>Mon, 08 Jun 2015 03:25:00 -0400</pubDate> <link>http://www.npr.org/sections/goatsandsoda/2015/06/08/412314701/lost-posture-why-indigenous-cultures-dont-have-back-pain?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/sections/goatsandsoda/2015/06/08/412314701/lost-posture-why-indigenous-cultures-dont-have-back-pain?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>There are a few populations in the world where back pain hardly exists. One woman thinks she has figured out why, and she's sharing their secrets. Have Americans forgotten how to stand properly?</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=412314701">» E-Mail This</a></p>]]></content:encoded> <dc:creator>Michaeleen Doucleff</dc:creator> </item> <item> <title>What Makes Algorithms Go Awry?</title> <description>Every time you "Like" a Facebook post, among other things, you help provide data to an algorithm. But algorithms, like the humans who design them, aren't foolproof — and can reflect bias.</description> <pubDate>Sun, 07 Jun 2015 17:27:00 -0400</pubDate> <link>http://www.npr.org/sections/alltechconsidered/2015/06/07/412481743/what-makes-algorithms-go-awry?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/sections/alltechconsidered/2015/06/07/412481743/what-makes-algorithms-go-awry?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>Every time you "Like" a Facebook post, among other things, you help provide data to an algorithm. But algorithms, like the humans who design them, aren't foolproof — and can reflect bias.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=412481743">» E-Mail This</a></p>]]></content:encoded> <dc:creator>NPR Staff</dc:creator> </item> <item> <title>Both Sides Claim Victory Over EPA Fracking Study</title>
<description>The Environmental Protection Agency has found no evidence that fracking has let to widespread, systemic pollution of water. Correspondent Jeff Brady tells NPR's Rachel Martin what the report means.</description> <pubDate>Sun, 07 Jun 2015 07:26:00 -0400</pubDate> <link>http://www.npr.org/2015/06/07/412633615/both-sides-claim-victory-over-epa-fracking-study?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/2015/06/07/412633615/both-sides-claim-victory-over-epa-fracking-study?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>The Environmental Protection Agency has found no evidence that fracking has let to widespread, systemic pollution of water. Correspondent Jeff Brady tells NPR's Rachel Martin what the report means.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=412633615">» E-Mail This</a></p>]]></content:encoded> </item> <item> <title>Once Feared, Now Celebrated, Hudson River Cleanup Nears Its End</title> <description>General Electric is entering the final year of a billion-dollar cleanup of PCB-contaminated water. The project was once controversial — now, even some early critics are asking for it to be continued.</description> <pubDate>Sat, 06 Jun 2015 17:15:00 -0400</pubDate> <link>http://www.npr.org/2015/06/06/412335354/once-feared-now-celebrated-hudson-river-cleanup-nears-its-end?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/2015/06/06/412335354/once-feared-now-celebrated-hudson-river-cleanup-nears-its-end?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>General Electric is entering the final year of a billion-dollar cleanup of PCB-contaminated water. The project was once controversial — now, even some early critics are asking for it to be continued.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=412335354">» E-Mail This</a></p>]]></content:encoded> <dc:creator>Brian Mann</dc:creator> </item> <item> <title>For New Mexico's Chiles, The Enemy Isn't Just Drought But Salt, Too</title> <description>Farmers in New Mexico are worried about the future of the state's most beloved crop: green and red chiles. They're increasingly relying on salty groundwater, which damages the soil and the crops.</description> <pubDate>Sat, 06 Jun 2015 07:34:20 -0400</pubDate> <link>http://www.npr.org/sections/thesalt/2015/06/06/412297396/for-new-mexicos-chiles-the-enemy-isnt-just-drought-but-salt-too?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/sections/thesalt/2015/06/06/412297396/for-new-mexicos-chiles-the-enemy-isnt-just-drought-but-salt-too?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>Farmers in New Mexico are worried about the future of the state's most beloved crop: green and red chiles. They're increasingly relying on salty groundwater, which damages the soil and the crops.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=412297396">» E-Mail This</a></p>]]></content:encoded> <dc:creator>Mónica Ortiz Uribe</dc:creator> </item> <item> <title>Schools Say Ciao To Plastic Lunch Trays, Hello To Compostable Plates</title> <description>Six of the nation's largest school districts are ditching polystyrene lunch trays in favor of compostable plates. The hope is that they'll incentivize cities to build more composting facilities.</description> <pubDate>Sat, 06 Jun 2015 06:48:15 -0400</pubDate> <link>http://www.npr.org/sections/thesalt/2015/06/06/411986584/schools-say-ciao-to-plastic-lunch-trays-hello-to-compostable-plates?utm_medium=RSS&utm_campaign=science</link> <guid>http://www.npr.org/sections/thesalt/2015/06/06/411986584/schools-say-ciao-to-plastic-lunch-trays-hello-to-compostable-plates?utm_medium=RSS&utm_campaign=science</guid> <content:encoded><![CDATA[<p>Six of the nation's largest school districts are ditching polystyrene lunch trays in favor of compostable plates. The hope is that they'll incentivize cities to build more composting facilities.</p><p><a href="http://www.npr.org/templates/email/emailAFriend.php?storyId=411986584">» E-Mail This</a></p>]]></content:encoded> <dc:creator>Maanvi Singh</dc:creator> </item> </channel></rss>