Results 1 to 5 of 5

Thread: Array problems!

  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default Array problems!

    How do I get a index on an array by using the value name.
    And how to I get the value name by using the index number?

  2. #2
    senorbum is offline Member
    Join Date
    Aug 2009
    Posts
    76
    Rep Power
    0

    Default

    Is this an array or array list?

    Say its an array.

    String[] someArray = {"dog", "cat"};

    in order to access objects knowing their index you can just say
    String animal = someArray[0];

    Knowing this, you should be able to figure out how to do so knowing the value and not the index.

  3. #3
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    sso i got to do a for looplike:
    Java Code:
    for (int x = 0;x<someArray.length;x++){
    if ( someArray[x].equals("myname")){
    ...
    ?

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Yes.
    Also read the tutorial.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Array problems..
    By smokeviolent in forum New To Java
    Replies: 1
    Last Post: 04-17-2009, 06:45 AM
  2. Array Index problems
    By ragnor2004 in forum New To Java
    Replies: 4
    Last Post: 03-26-2009, 07:53 PM
  3. Array problems
    By Hosticus in forum New To Java
    Replies: 2
    Last Post: 01-18-2009, 02:48 AM
  4. array problems need your help ASAP!
    By notherand in forum New To Java
    Replies: 1
    Last Post: 06-29-2008, 08:59 PM
  5. problems with array index
    By mary in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 04:30 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
  •