Results 1 to 2 of 2
  1. #1
    Igor is offline Member
    Join Date
    Dec 2007
    Posts
    3
    Rep Power
    0

    Default reference to elements in array

    I'm working with a username system that retrieves every ID and sees if there is a name attached to that specific ID. Since the great majority of ID's does not have a name attached to it, it takes quite some unnecessary time. To prevent this, I'd like to try the following:

    int [] usedIDs = {1,6,34,69,306,486 etc...};

    for (int i = 0; i < usedIDs.length; i++) {
    //System.out.println(usedIDs[i]);
    }

    and then, to from there on handle the IDs that are filled as just an integer.
    So something like:

    int usedID = usedIDs[1];
    int usedID = usedIDs[2];
    etc.

    Which of course doesn't really work. So I want it to, with increments by one, go through every instance of usedIDs[n] and pass that simple integer on to the rest of the program.
    I suspect I need another loop somewhere, but anyone have any concrete ideas on how to fix this?

    thanks,

  2. #2
    Abdul Ajis is offline Member
    Join Date
    Dec 2007
    Posts
    12
    Rep Power
    0

    Default

    Hey try to use HashMap , put your id as a key and value as what u want

    Then whenever the id comes in , you can easily pick up from the hashmap

    Hope this fix your issue , this way u can reduce loops

Similar Threads

  1. Object and reference
    By katie in forum New To Java
    Replies: 2
    Last Post: 10-19-2009, 03:45 PM
  2. Replies: 0
    Last Post: 04-15-2008, 08:12 AM
  3. Getting the Object Reference Name
    By Deathmonger in forum New To Java
    Replies: 2
    Last Post: 03-12-2008, 02:51 PM
  4. Replies: 1
    Last Post: 12-14-2007, 07:25 AM
  5. Help with array of elements
    By zoe in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 05:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •