차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
다음 판 | 이전 판 | ||
tech:java_string_comparison [2012/08/22 00:05] – 새로 만듦 211.56.252.201 | tech:java_string_comparison [2016/07/12 00:56] (현재) – 바깥 편집 127.0.0.1 | ||
---|---|---|---|
줄 1: | 줄 1: | ||
+ | {{tag> | ||
+ | ======Java String Comparison====== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | String Comparison | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | Strings can not be compared with the usual <, <=, >, or >= operators, and the ===== and != operators don't compare the characters in the strings. | ||
+ | Comparing objects vs. primitive types | ||
+ | |||
+ | [to be supplied] | ||
+ | |||
+ | Comparing Strings: =====, .equals(), .compareTo(), | ||
+ | To compare Strings for equality, don't use =====. The ===== operator checks to see if two objects are exactly the same object. Two strings may be different objects, but have the same value (have exactly the same characters in them). Use the .equals() method to compare strings for equality. Similarly, use the .compareTo() method to test for unequal comparisons. For example, | ||
+ | String s = " | ||
+ | |||
+ | <code java> | ||
+ | if (s.equals(t)) // RIGHT | ||
+ | if (s > t) // ILLEGAL | ||
+ | if (s.compareTo(t) > 0) // CORRECT></ | ||
+ | |||
+ | |||
+ | Comparing without regard to case | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | * 출처: [[http:// | ||
+ | |||
+ | ^ 누구나 수정하실 수 있습니다. | ||
+ | |||