본문 바로가기

개발/JAVA

[생활코딩] 제어문 - 문자의 비교 : ==과 equals의 차이점

https://opentutorials.org/course/3975/26781

 

문자의 비교 : ==과 equals의 차이점 - 생활코딩

수업소개 자바에서 문자나 객체를 비교할 때는 ==가 아닌 equals를 사용해야 합니다. 그 이유와 equals의 의미를 살펴봅시다.  강의 소스코드 public class AuthApp2 { public static void main(String[] args) { String i

opentutorials.org

 

public class AuthApp {

 

public static void main(String[] args) {

 

System.out.println(args[0]);

 

String id = "egoing";

String inputId = args[0];

 

System.out.println("Hi.");

 

// if (inputId == id) {

if(inputId.equals(id)) {

System.out.println("Master!");

}

else {

System.out.println("Who are you?");

}

 

}

 

}