String s1="str";equals()는 대소문자를 구분합니다(소문자 또는 대문자):
문자열 s2="str";
if(s1.equals(s2))
System.out.println("두 문자열이 모두 동일함");
String s1="str";이 경우 false.
문자열 s2="STR";
if(s1.equals(s2))
System.out.println("두 문자열이 모두 동일함");
String s1="str";
문자열 s2="STR";
if(s1.equalsIgnoreCase(s2))
System.out.println("무시된 대/소문자 민감도. 두 문자열이 동일합니다.");
if("string1".length()=="string2".length())
System.out.println("string1 및 string2 크기가 같음");
else if("string1".length()>" string2".length())
System.out.println("string1이 더 깁니다.");
else
System.out.println("string2가 더 깁니다.");
new String("test").equals(new String("test"));//--> true"==" 연산자는 객체의 동등성을 테스트하며, 피해야 할 일련의 오류는 다음과 같습니다.
String s1="trial";연결은 런타임에 호출되는 substring()과 replace()와 달리 컴파일 중에 호출되기 때문에 true를 반환하고 수식의 다른 쪽과 같지 않은 새 객체가 만들어집니다.
String s2="평가판";
//같은 객체입니다
s1==s2; --> false
//같은 객체가 아닙니다
s1 == "test"; --> false
//같은 객체를 참조합니다
"test" == "test"; --> true
//연결은 단일 객체로 간주됩니다
"test" == "your"+"t"; --> true
//substring() 메서드는 새로운 객체를 생성합니다
"test" == "1test".substring(1); --> false
//replace() 메서드는 새 객체를 생성합니다
"test" == "Test".replace("T", "t"); --> false
Please disable your ad blocker and refresh the window to use this website.