Review

Java String Comparison Tutorial (Equals vs == in Java)

Rate this post



Full Java Course:

I recommend installing Tabnine autocomplete on your IDE (free):

You can compare strings in Java with either == or equals(). This video goes over when to use each. Most of the time you’ll want to use equals to compare strings in Java because it compares the contents, not the object itself.

I hope you enjoyed this Java string comparison tutorial!

Free tips and programs:

Recommended Channels to Subscribe to
Career Karma:
TheNewBoston:

~

(2nd channel)

Alex Lee

Tag: equals java, java string, java strings, java string comparison, java string compare, string methods in java, java equals method, java equals vs ==, string equals vs == java, java strings tutorial, alex lee java strings, alex lee, java, compare strings, compare string in java, string equals java

Xem thêm: https://blogthủthuật.vn/category/review

Nguồn: https://blogthủthuật.vn

33 Comments

  1. Alex you are a good tutor, keep uploading new videos,don't worry i am daily at your videos,make easy videos and tutorials for evrything of java and i mean everything
    LOL

    Reply
  2. i have a question but it is not reffering to java – Which video screen capture are you using ? and how do you do that thing that i see your screen and a little screen of you on buttom ?

    Reply
  3. Hey! How can I search for a part of a string in an array or text file?
    So just putting in "ong" should recognize the whole Object "Happy Song".
    Thanks prior for the answer!

    Reply
  4. I think that what makes your videos better than most comp sci courses is that cs professors assume you have a perfect grasp on everything learned up to that topic while you assume that I don't know anything about anything…

    Reply
  5. The == operator checks if both variables points to the same memory location. So when you compared String a = "lemur" to String b = "lemur" the operator == returns true because, since both variable a and b are allocated a similar String value. The compiler will store a single copy of that value. Meaning that both variable a and b will point to the same address/memory location. This feature is called "interning". When you declared String a = new String("lemur") and String b = new String("lemur"). The compiler creates two objects that are stored in separate memory locations. So of course the == will return false. What the equals() method does is. It compares the value stored by two objects irrelevant of their memory location. Hope this makes it easier to remember the difference between the two.

    Reply

Post Comment