char ch = 'a';
if(ch == 'a'){
}
이런식으로 논리연산자를 써서 비교.
하지만 문자열 비교는
String str = "hello";
if(str == "abc"){
}
이렇게 논리연산자로 비교하면 안된다.
if(str.equals("hello")){
}
.equals메소드를 이용하여 비교해주어야 한다.
if(str.equals("c") || str.equals("C")){}
if(str.equalsIgnoreCase("c")){} // 대소문자 구분x
.equalsIgnoreCase()메소드는 대소문자 구분없이 비교한다.
str = "3";
if(str!=null && !str.equals("")){
char ch = str.charAt(0);
}
str!=null로 먼저 null체크를 해주어야함.
안그러면 str.equals("") 메소드를 불러올 때 오류발생.
0.0과 10.0사이의 double값을 반환한다. (0.0 <= Math.random() < 1.0)