Alternative to switch case


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Alternative to switch case

  1. #1
    Join Date
    Feb 2006
    Posts
    11

    Alternative to switch case

    I'm sure this is a problem that almost everyone has dealt with:
    Any suggestions on how to work a switch statement with a string?

    I have a string array, where I want to base my switch on the first element.
    The first element can have about 25+ different values. This makes using a hashcode a bit on the awkward side, since there will be no way to keep track of what each case is for. (Well placed comments would do it, but doesn't help much with making the code readable.)

    Should I make an enum for all possible values and have a call to assign one for my switch. This seems like a bit of overkill.

    Or is there something else that may work better?

  2. #2
    Join Date
    Mar 2006
    Posts
    16

    use if loops or make ur own class

    Hey

    you can do this way -
    1. use if..else..if statement
    2. to comparing string object use :- stringObj1.compareTo(stringObj2)

    or u can write ur own class and mention if else statements and while using it make it like stitch statement,
    in C switch statement is internally multiple if statements , in Java I have not tried yet. just check it.


    Cheers,
    Rohan Chandane

  3. #3
    Join Date
    Feb 2006
    Posts
    11
    Thanks for the suggestion.
    I don't think this is feasible, since there are about 50 upper level (if else if) categories, and most of these will have sub-levels.
    I've seen some fancy enumeration classes, so I'll look at those and see if that will work.

Similar Threads

  1. Why is this in the console?
    By Dark Rain in forum Java
    Replies: 8
    Last Post: 09-30-2005, 07:42 PM
  2. Run-time error by a blank record made by code
    By VanDam in forum Database
    Replies: 0
    Last Post: 07-09-2005, 05:18 AM
  3. Use of Select Case or Switch Statement
    By Daryl Shockey in forum Database
    Replies: 2
    Last Post: 05-28-2002, 04:50 PM
  4. Writing in HKEY_LOCAL_MACHINE...Access is denied
    By Martin in forum VB Classic
    Replies: 22
    Last Post: 12-03-2001, 04:53 AM
  5. ADOX problem
    By Yoel Martinez in forum VB Classic
    Replies: 1
    Last Post: 12-12-2000, 04:17 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center