Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: string.equals(anotherString) Anything like this for doesn't equal?

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default string.equals(anotherString) Anything like this for doesn't equal?

    Hello, I'm just wondering if there is anything for something like string.notequal(anotherString). Basically, in my while loop, I want it to keep asking the size of the pizza they want if the input string doesn't equal any of the three final Strings. Thanks so much for any help in advance! (I know != and == do not work with Strings, that is just there to help point out my question. I also tried something along the lines of:

    while(input.compareTo(SMALL) == 1

    import javax.swing.JOptionPane;
     
    public class TestPizza
    {
        public static String input;
        public static String pSize;
        public static String stringSize;
        final static String LARGE = "Large";
        final static String SMALL = "Small";
        final static String MEDIUM = "Medium";
     
        public static void main(String[] args)
        {
            input = JOptionPane.showInputDialog("Enter the size of pizza you want" +
                "(Small, Medium, or Large:");  
     
            Pizza pizzaSize = new Pizza(input);
     
            while(input != SMALL)
            {
                JOptionPane.showMessageDialog(null, "You've entered an invalid" +
                    " size");
                input = JOptionPane.showInputDialog("Enter width of room:");
            }
     
            pizzaSize.display(input);
       }
    }

    Thanks again for any help!


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,262
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: string.equals(anotherString) Anything like this for doesn't equal?

    equals returns a boolean, which you can then use !=, or shorthand !

    String myString = "myString";
    if ( !myString.equals("not") ){
        System.out.println("myString does not equal not");
    }
    if ( myString.equals("not") != true ){//or == false
    //
    }

Similar Threads

  1. [SOLVED] Difference between == and equals.
    By goldest in forum What's Wrong With My Code?
    Replies: 9
    Last Post: December 18th, 2010, 02:15 PM
  2. While JOptionPane equal Yes????
    By maximus20895 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 20th, 2010, 08:57 PM
  3. Nested Looping to find if Strings equal
    By aussiemcgr in forum Loops & Control Statements
    Replies: 4
    Last Post: July 9th, 2010, 03:08 PM
  4. Replies: 2
    Last Post: February 25th, 2010, 03:17 PM
  5. Equals Method
    By Sninald in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 18th, 2010, 02:06 AM