Algorithm 6-6: dictionary application of hash table Application

Source: Internet
Author: User

The purpose of this application is to query CSV files.


Running example

java QueryCSV dns.csv 0 1baidu.com123.125.114.144zjgsu.edu.cn202.96.99.58


Code

The Java standard library of Princeton University is used in the Code. Please click here to download: http://introcs.cs.princeton.edu/java/stdlib/


Import java. util. hashMap; import java. util. linkedHashMap; public class QueryCSV {public static void main (String [] argv) {In in = new In (argv [0]); int keyField = Integer. parseInt (argv [1]); int valueField = Integer. parseInt (argv [2]); // create a hash table HashST
 
  
Map = new HashST
  
   
(); While (! In. isEmpty () {String line = in. readLine (); String [] s = line. split (","); map. put (s [keyField], s [valueField]);} // process the query operation while (! StdIn. isEmpty () {String key = StdIn. readString (); String value = map. get (key); if (value = null) StdOut. println ("Not Found"); else StdOut. println (value );}}}
  
 


Dns.csv File Content

baidu.com,123.125.114.144zjgsu.edu.cn,202.96.99.58abc.com,199.181.132.250


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.