Zoltan が正しく指摘しているように、彼以外のすべての答えは実際には間違っています。
サードパーティのライブラリの機能を使用するには、次のことをお勧めしhamcrest
ます。
import static org.hamcrest.text.IsEqualIgnoringWhiteSpace.equalToIgnoringWhiteSpace;
public class Main {
public static void main(String[] args) {
String a = "VIJAY KAKADE";
String b = "VIJAY KAKADE";
System.out.print(String.format("'%s' and '%s' matching: ", a, b));
if (equalToIgnoringWhiteSpace(a).matches(b)) {
System.out.println("yes");
} else {
System.out.println("no");
}
String c = "VIJAYKAKADE";
System.out.print(String.format("'%s' and '%s' matching: ", a, c));
if (equalToIgnoringWhiteSpace(a).matches(c)) {
System.out.println("yes");
} else {
System.out.println("no");
}
}
}
戻り値:
'VIJAY KAKADE' and 'VIJAY KAKADE' matching: yes
'VIJAY KAKADE' and 'VIJAYKAKADE' matching: no