ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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 Entry.java, which describes each entry into the address book - name, number, address, comments.
In the main class, Address.java, 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.
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.