Results 1 to 2 of 2
  1. #1
    ShaneO is offline Member
    Join Date
    May 2012
    Rep Power

    Question [Solved] How do I do a simple compare in java (within an IF)???

    I'd think this would be much easier than it actually is....

    All I want is to compare one string with another (I've hard coded one of the strings for now - for simplicity), and return a TRUE or a number that makes sense (like a 0).

    Here is what I've tried:

    Java Code:
    if (submitForm.getStrType().equalsIgnoreCase("Advice")) {
    } else {
        ps.setInt(7, submitForm.getIntWords());
    I've also tried:
    Java Code:
    if (submitForm.getStrType() == "Advice")
    Java Code:
    if (submitForm.getStrType().compareToIgnoreCase("Advice"))
    ... all with no success (it always fails and goes to the 'else' statement)

    I've confirmed that submitForm.getStrType() returns "Advice" (see attachment)


    EDIT: My apologies. Issue has been solved (was a web publishing issue - not a syntax issue)
    Attached Thumbnails Attached Thumbnails [Solved] How do I do a simple compare in java (within an IF)???-untitled.png  
    Last edited by ShaneO; 09-30-2013 at 07:48 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power

    Default Re: How do I do a simple compare in java (within an IF)???

    What String are you passing in to the comparison? Create an SSCCE where the String is hardcoded so we can see exactly what you're doing.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. Replies: 6
    Last Post: 09-19-2013, 04:06 AM
  2. Compare XML in Java
    By SmittyWerben in forum New To Java
    Replies: 8
    Last Post: 08-27-2013, 06:37 PM
  3. Java code to compare 2 PDF files
    By Shanthuday in forum Forum Lobby
    Replies: 2
    Last Post: 01-08-2013, 12:55 PM
  4. Replies: 4
    Last Post: 01-03-2013, 06:55 PM
  5. compare sensorvalue leJOS, java for LEGO NXT
    By reinout91 in forum New To Java
    Replies: 0
    Last Post: 06-22-2011, 12:53 AM

Tags for this Thread

Posting Permissions

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