tree map help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: tree map help

  1. #1
    Join Date
    Nov 2003
    Posts
    1

    tree map help

    I have written the code below, but now i am compleatly stuck!! i need to change this code to read in a name from the user then search the treemap for that name and return that name.
    The names are stored in a txt file like:
    john anderson:0123456322
    jim collet:0176849323
    Is it possible to put these names and number in the tree map, and have name as a key and number as a value, then search the treemap?? pls help!!

    Code:
    class Treemap {  
      public static void main(String[] args) {     
        Map phoneBook = new TreeMap();    
        BufferedReader in = new BufferedReader(new FileReader("directory.txt"));    
        String line;     
        while ((line = in.readLine()) != null) {        
          String line = in.readLine();             
          int pos = line.indexOf (":");      //So use String.substring to get the parts of the line.           
          String name = line.substring (0, pos);            
          String number = line.substring (pos + 1);
          phoneBook.put (name, number);
    [ArchAngel adjusted text in CODE tags so that it's not all on one line]

  2. #2
    Join Date
    Mar 2003
    Posts
    834
    I'm confused. What's the problem? You've already populated the Map with the data from the file.
    ArchAngel.
    O:-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center