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

    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")) {
        ps.setInt(7,0);
    } 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)

    Thanks!


    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 06:48 PM.

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

    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 - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

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

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
  •