Running the lookup program… I had to remove blanks from state names because of the way I read in strings

 

c:\Program Files\Java\jdk1.6.0_03\bin>java LookUp states.txt GEORGIA ARKANASA AR

KANSAS MICHIGAN IIOWWW IOWA PALAU OHOI  OHIO  SOUTHDAKOTA

Keys are: State values are: Abbreviation

GEORGIA has value GA

ARKANASA has no value in this map

ARKANSAS has value AR

MICHIGAN has value MI

IIOWWW has no value in this map

IOWA has value IA

PALAU has value PW

OHOI has no value in this map

OHIO has value OH

SOUTHDAKOTA has value SD

 

A tree map that will provide key/value lookup for any sort of data, as long as it has the right format

c:\Program Files\Java\jdk1.6.0_03\bin>

 

import java.util.*;

import java.io.*;

public class LookUp{

public static void main(String args[]){

if(args.length<1)System.exit(1);

try{

FileInputStream fis=new FileInputStream(args[0]);

Scanner s=new Scanner(fis);

TreeMap tm=new TreeMap();

String key=s.next();

String value=s.next();

System.out.println("Keys are: "+key+" values are: "+value);

while(s.hasNext()){

   key=s.next("\\w+");

   value=s.next("\\w+");

   //System.out.println("Keys are: "+key+" values are: "+value);

   tm.put(key,value);   }

for(int i=1;i<args.length;i++)

{ key=args[i];

  if(tm.containsKey(key))

  {String val=(String)tm.get(key);

  System.out.println(key+" has value "+val);  }

else System.out.println(key+" has no value in this map");

}//for

}catch(IOException e){System.out.println("ioerror");}

}}

 

 

 

 

 

 

 

 

 

Famous data/events tree map

 

import java.util.*;

 

public class TreeMapTester{

public static void main(String args[]){

TreeMap treemap=new TreeMap();

treemap.put(new Integer(1066),"Norman Invasion");

treemap.put(new Integer(1865),"Gettysburg Address");

treemap.put(new Integer(1775),"Revolutionary War");

treemap.put(new Integer(1452),"Gutenberg Bible");

treemap.put(new Integer(1918),"World War I");

treemap.put(new Integer(1941),"World War II");

treemap.put(new Integer(1962),"John Glenn/Mercury Capsule flight");

treemap.put(new Integer(1969),"Apollo 11 Moon Landing");

treemap.put(new Integer(1564),"Galileo's birthday");

 

System.out.println("first key: "+treemap.firstKey().toString()+"last key: "+treemap.lastKey().toString());

}}

 

 

C:\PROGRA~1\JAVA\JDK15~1.0_0\BIN>java TreeMapTester 1962

first key: 1066last key: 1969

John Glenn/Mercury Capsule flight

 

C:\PROGRA~1\JAVA\JDK15~1.0_0\BIN>java TreeMapTester 1963

first key: 1066last key: 1969

1963is not a key or not provided

 

C:\PROGRA~1\JAVA\JDK15~1.0_0\BIN>java TreeMapTester

first key: 1066last key: 1969

 

C:\PROGRA~1\JAVA\JDK15~1.0_0\BIN>java TreeMapTester 1775

first key: 1066last key: 1969

Revolutionary War

 

C:\PROGRA~1\JAVA\JDK15~1.0_0\BIN>