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!!
[ArchAngel adjusted text in CODE tags so that it's not all on one line]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);


Reply With Quote


Bookmarks