자바 문자열 비교 함수 .equals() 사용법 및 간단한 예시 코드 결과값 - 개발새발 작성 일기

개발새발자·2023년 10월 28일
1

자바 개념

목록 보기
6/15

.equals() 함수

  • 값 비교할 때 사용하는 함수
public class SampleEquals {

    static void equalsshow(String str1, String str2) {
        if (str1.equals(str2)) {
            System.out.println('"' + str1 + '"' + " and " + '"' + str2 + '"' + " are the same");
        }
        else {
            System.out.println('"' + str1 + '"' + " and " + '"' + str2 + '"' + " are not the same");
        }
    }
        public static void main(String[] args) {
        String apple = "apple";
        String banana = "banana";

        equalsshow(apple, banana);
    }
}

결과

"apple" and "banana" are not the same

profile
바삭하고 촉촉한 쿠키로 살자

0개의 댓글