Results 1 to 4 of 4
  1. #1
    LoliChin is offline Member
    Join Date
    May 2014
    Posts
    2
    Rep Power
    0

    Default Error comparing Strings

    I was writing a code to have the library books classified in name, author, area, ed, etc. I'm using NetBeans and it doesn't accuse any error. But when I run the project, it never goes right and shows the books only in one area, regarthless what I type. (The goal of the algorithm is to separate the books in areas (sciences, humanities and biological science);
    I'm adding the code as an attachment.
    PS: The Strings are in portuguese, sorry =p
    Attached Files Attached Files

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,404
    Rep Power
    25

    Default Re: Error comparing Strings

    Please post the code here that you are asking about.
    The equals() method should be used to compare Strings. Don't use the == operator.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: Error comparing Strings

    Please read about switch statements again. Keep care of the falling through behaviour!

    And even that Java 7 introduced switch statements with strings: It seems that you want to ignore the case so the propper equalsIgnoreCase call is the prefered solution in my eyes.

  4. #4
    LoliChin is offline Member
    Join Date
    May 2014
    Posts
    2
    Rep Power
    0

    Default Re: Error comparing Strings

    Thank you guys, it really helped a lot.

Similar Threads

  1. Comparing Strings
    By allaudin in forum New To Java
    Replies: 3
    Last Post: 07-01-2013, 05:03 PM
  2. Comparing Strings
    By Adomini in forum New To Java
    Replies: 3
    Last Post: 02-17-2011, 12:20 AM
  3. comparing strings
    By diggitydoggz in forum New To Java
    Replies: 7
    Last Post: 12-23-2008, 04:40 AM
  4. Comparing Strings
    By souFrag in forum Advanced Java
    Replies: 5
    Last Post: 05-21-2008, 09:03 AM
  5. Comparing Strings
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 09:44 AM

Posting Permissions

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