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

Комментарии • 23

  • @BillBarnum
    @BillBarnum  4 года назад

    📌 Subscribe For The Latest Videos: bit.ly/36H70sy 📌
    .
    💻 All Java Tutorials: bit.ly/JavaTutorialsRUclips 💻
    .
    🤖 Learn Java In 3 Hours: bit.ly/JavaIn3Hours 🤖

  • @foamersimpson6690
    @foamersimpson6690 11 месяцев назад +1

    These videos are amazing and help me understand concepts that I didn't even know existed. Thank you bill!

  • @abhisheknagarkar6254
    @abhisheknagarkar6254 2 года назад +1

    Really liked your video.. Super awesome explanations with just the right amount of info so a person watching the video isn't flooded !

  • @sergeiflozov91
    @sergeiflozov91 4 года назад +3

    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 ^^

  • @glokta1
    @glokta1 4 года назад +1

    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!

    • @BillBarnum
      @BillBarnum  4 года назад

      Thanks for the feedback.

  • @satioOeinas
    @satioOeinas Год назад

    great video.

  • @PrinceZam
    @PrinceZam 2 года назад +1

    Wow this is really cool 🗣💯

    • @BillBarnum
      @BillBarnum  2 года назад

      Thanks for the feedback. I'm glad you liked the video!

  • @makemusic1014
    @makemusic1014 3 года назад +1

    I wish u were my tutor

  • @Bettle
    @Bettle 4 года назад +1

    Good job

  • @cheribgh275
    @cheribgh275 7 месяцев назад

    Hi Bill, can we initialize arraylist like this?
    List myList = new ArrayList();
    I mean is this the right way?

    • @BillBarnum
      @BillBarnum  7 месяцев назад

      That would be fine. Alternatively: ArrayList myList = new ArrayList();
      ArrayList Video: ruclips.net/video/hJobOCPNnsc/видео.html&pp=ygUOYXJyYXlsaXN0IGphdmE%3D

  • @kimsungho4114
    @kimsungho4114 3 года назад +1

    I watched all the ads for you :)

  • @RakibHasan-455
    @RakibHasan-455 2 года назад +1

    7:44 can anyone tell me why it returns false,,, but in Arraylist it returns true..

    • @BillBarnum
      @BillBarnum  2 года назад +2

      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

    • @RakibHasan-455
      @RakibHasan-455 2 года назад

      @@BillBarnum Thanks man!

  • @ZXu-mj9gm
    @ZXu-mj9gm 3 года назад +1

    👍

    • @BillBarnum
      @BillBarnum  3 года назад

      Thanks for the feedback!

  • @sdanikazmi
    @sdanikazmi 2 года назад

    7:50 mistake on line a.equals(c) will be true.

    • @BillBarnum
      @BillBarnum  2 года назад

      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.