Checking Equality in Java ( == vs equals method )
HTML-код
- Опубликовано: 8 сен 2024
- This Java tutorial for beginners explains different ways to check if two variables are equal including ==, the equals() method, and Arrays.equals().
Specifically, we discuss primitive types including int, double, and boolean. Also included are explanations for the array class, ArrayList class, and String class.
Aligned to AP Computer Science A.
🔥 Subscribe To Get More Tutorials: bit.ly/36H70sy 🔥
🖥️ All Java Tutorials: bit.ly/JavaTuto... 🖥️
#Java #JavaTutorial #JavaTutorials
📌 Subscribe For The Latest Videos: bit.ly/36H70sy 📌
.
💻 All Java Tutorials: bit.ly/JavaTutorialsRUclips 💻
.
🤖 Learn Java In 3 Hours: bit.ly/JavaIn3Hours 🤖
These videos are amazing and help me understand concepts that I didn't even know existed. Thank you bill!
Really liked your video.. Super awesome explanations with just the right amount of info so a person watching the video isn't flooded !
Awesome, thank you!
Seems like there is a typo in 11:00 .. the quotation is not closed inside the parentheses of the println method in the second if statement! Your video is helping me a lot Thanks ^^
Wow, good catch!
God bless you, I've been racking my brain against this for hours and this video was exactly what I needed. Very clear presentation. Your "Primitive vs Reference Type Objects in Memory" was also very helpful. Thanks a lot!
Thanks for the feedback.
great video.
Wow this is really cool 🗣💯
Thanks for the feedback. I'm glad you liked the video!
I wish u were my tutor
Good job
Hi Bill, can we initialize arraylist like this?
List myList = new ArrayList();
I mean is this the right way?
That would be fine. Alternatively: ArrayList myList = new ArrayList();
ArrayList Video: ruclips.net/video/hJobOCPNnsc/видео.html&pp=ygUOYXJyYXlsaXN0IGphdmE%3D
I watched all the ads for you :)
7:44 can anyone tell me why it returns false,,, but in Arraylist it returns true..
Good question.
The Java object class includes an equals method that checks if the variables point at the same object. For classes, like arrays, that inherit the equals from the Java object class, using == and .equals() is equivalent.
In classes like ArrayList, the .equals() method was overridden, and it actually checks the VALUES in the objects the variables are pointing at. In those cases, using .equals will return true if the two variables point at different objects with equal values.
I don't have a video on it, but if you search RUclips for "overriding equals java," you can learn what it means to override the equals method.
If you want to learn more about inheritance in general, or overriding in general, I have some videos on those topics: ruclips.net/p/PLmpmyPywZ443dRtMleUPoNp2OyiNE45O6
@@BillBarnum Thanks man!
👍
Thanks for the feedback!
7:50 mistake on line a.equals(c) will be true.
Syed,
This is an example of how confusing it can be to check equality in Java.
While they are equivalent arrays, if you compare them that way, it will evaluate to false because the variables aren't pointing at the same object.
At 11:20, I talk about the correct way to check the equivalency of two arrays.