How to group all the items into array and check them?

Discussion in 'Java' started by cybernerdsx2@yahoo.com, Feb 7, 2005.

  1. Guest

    Hi,

    I would like to list all the error codes into a fixed array and then
    use it to check if the item falls into the array.

    Something like psudo code below:

    if ( errorCode isIn errorsArray[] ) then
    Display "Error found matching inside the array"
    Else
    Display "No macthing error found"

    Is there such a keyword found in Java? Or is there such a method to do
    it?
    , Feb 7, 2005
    #1
    1. Advertising

  2. > I would like to list all the error codes into a fixed array and then
    > use it to check if the item falls into the array.
    >
    > Something like psudo code below:
    >
    > if ( errorCode isIn errorsArray[] ) then
    > Display "Error found matching inside the array"
    > Else
    > Display "No macthing error found"
    >
    > Is there such a keyword found in Java? Or is there such a method to do
    > it?


    if your error code just numbers from 0 till xxx, then you can just
    if(errorCode < errorsArray.length) { ....//errorCode is an int

    if not you can put them into Hashtable and do following
    if(errosTable.get(errorCode) != null) {... //errorCode is Object

    in worst case you can search your array:
    for(int i = 0; i < errorsArray.length;i++) {
    if(errorsArray == errorCode) {... //errorCode is an int
    }

    --
    Andrey Kuznetsov
    http://uio.dev.java.net Unified I/O for Java
    http://reader.imagero.com Java image reader
    http://jgui.imagero.com Java GUI components and utilities
    Andrey Kuznetsov, Feb 7, 2005
    #2
    1. Advertising

  3. Wendy S Guest

    "Andrey Kuznetsov" <> wrote

    > if not you can put them into Hashtable and do following
    > if(errosTable.get(errorCode) != null) {... //errorCode is Object


    I was also going to suggest a Map.

    If you just need to know whether it's in there (and not retrieve it):
    if( errorsTable.containsKey( errorCode) ) { ... }

    --
    Wendy
    Wendy S, Feb 7, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anonieko

    HttpHandlers - Learn Them. Use Them.

    Anonieko, Jun 15, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    506
    tdavisjr
    Jun 16, 2006
  2. Anjan Bhowmik
    Replies:
    1
    Views:
    457
    Misbah Arefin
    Feb 14, 2008
  3. why the lucky stiff
    Replies:
    5
    Views:
    133
    why the lucky stiff
    Sep 22, 2004
  4. Suresh
    Replies:
    2
    Views:
    383
    Suresh
    Apr 22, 2004
  5. ela
    Replies:
    12
    Views:
    329
    Uri Guttman
    Apr 6, 2009
Loading...

Share This Page