Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-16-2002, 09:43 PM   #1
Registered: Sep 2001
Location: Salt Lake City
Distribution: Slackware 8.1
Posts: 133

Rep: Reputation: 15
java data structures

I am fairly new to programming, and am writing a simple GUI address book in java. (This is _not_ any kind of homework problem, just for fun).

I have a simple class called, which describes each entry into the address book - name, number, address, comments.

In the main class,, the GUI is drawn, and action events such as "Add entry", "Delete entry" etc. are handled.

The GUI uses tabs to move between different functions of the address book (as in add, delete, search). The first tab displays the entries by first name, last name, and number, a-c, d-f, etc, each again tabbed (sounds a bit confusing, but is actually easy to work with).

I am currently using java's TreeMap to hold all the entries, because they will be ordered, and give fast look up times. I need them to be ordered so that the panel the panel that displays the lists of names, can simply iterate through each name and decide on which subpanel to draw it to (m-0, or x-z for example).

My question is - how might I handle duplicate entries. I am now using the first name as a key to the TreeMap, so they can be ordered by first name. I need to be able to handle mulitple identical first names. If I map the entries using, say, the phone number, I could have multiple identical first names, but then they won't be in the order.

I think I need use a different data structure, say an ArrayList, and then when I want the panel to display the names in order, dump the ArrayList into something else that can order them. But not sure how I could do this - short of write my own implementation of ArrayList and add an sort() method.

Any ideas would be appreciated.
Old 12-16-2002, 10:31 PM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
You might look at hashtables ... that's a structure that supports
unique entries ...

Old 12-17-2002, 12:00 AM   #3
Registered: Sep 2001
Location: Salt Lake City
Distribution: Slackware 8.1
Posts: 133

Original Poster
Rep: Reputation: 15
Well, from what I can tell in the api is that Hashtable implements the Map interface, which doesn't allow duplicates. And I need both duplicates and sorting. I would like to be able to have two identical entries in to the Address book.

So using an Array or Linked list would allow the duplicates, but then I'd have to sort them some other way.

Using a TreeMap would sort them as I entered them, but not allow duplicates.

Using some Hashing implementation wouldn't let me do either.

That's why I'm thinking ArrayList, and then have a sorting function built in. So each time I added an entry, I would just call my sort() method on it right after.

Please correct me if my understanding is off - still new to this.
Thanks again.
Old 12-17-2002, 07:14 AM   #4
Registered: Aug 2001
Posts: 60

Rep: Reputation: 15
cant u use mulitmap kind of thing which will support duplication
Old 12-17-2002, 11:51 AM   #5
Registered: Sep 2001
Location: Salt Lake City
Distribution: Slackware 8.1
Posts: 133

Original Poster
Rep: Reputation: 15
Thanks, that was a good keyword, found lots of folks classes named that. Will see about adding that package.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data structures - Trees rahul_kulkarni Programming 1 05-16-2005 05:45 AM
[java]removing unwanted data from a file djadhav Programming 1 10-24-2004 08:32 AM
JAVA:Problems in Displaying Data to Terminal.. nedian123 Programming 1 07-06-2004 10:13 PM
perl->large data structures->copying lackluster Programming 0 08-20-2003 10:27 AM
Are there man pages for data structures? concoran Programming 3 07-05-2002 03:07 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:04 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration