Java String Comparison Methods - equals equalsIgnoreCase compareTo - Java Programming - Appficial

Поделиться
HTML-код
  • Опубликовано: 6 ноя 2024

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

  • @Appficial
    @Appficial  5 лет назад +1

    Please SUBSCRIBE! More programming videos coming soon! ✌️

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

    Thank you

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

    And if i want compare 3 strings: for example: "kali, karkiv, karola" ? How can i do it at the same time? and how put in order in a list?

    • @Appficial
      @Appficial  Год назад +1

      Use && for compound expressions. Then use arrays or ArrayList to store them in a list. I have videos on both

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

      @@Appficial , oh thank you a lot. I will try to find this videos :)

    • @youtriggered8179
      @youtriggered8179 11 месяцев назад

      where are those videos?@@Appficial

  • @ralphmoreno2974
    @ralphmoreno2974 6 лет назад +2

    Great video!

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

    Thank u ❤️

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

    Question, sir: Could you use these methods to sort a 2D string array so that the array elements are sorted from A to Z? I have seen some videos related to this, but not exactly what I need. I have a project concerning this and for some reason, there is one piece that is giving me a bit of trouble.
    This is some of the relevant code right here:
    for(int i=0; i>numberOfRows; i++) {
    if(statesCapitals[i].compareToIgnoreCase(statesCapitals[i-1]) > 0) {
    temp = statesCapitals[i];
    statesCapitals[i] = statesCapitals[i-1];
    statesCapitals[i - 1] = temp;
    }
    My compareToIgnoreCase is giving me an error: Cannot invoke compareToIgnoreCase(String[]) on the array type String[].
    I'm not exactly sure what's wrong with the code since both elements are strings. Any help would be appreciated! Thanks!

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

      For a 2D array, you would loop through each element and sort it, since each element is also an array. Since you are working with Strings, you can just use the Comparator sort() method

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

      @@Appficial Thank you for the help, sir!