equals()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@Test
public void equals_구현_테스트() {
String a = "asdasd";
String b = "asdasd";
assertThat(equals(a, b)).isTrue();
}
private boolean equals(String a, String b) {
char[] caa = a.toCharArray();
char[] cab = b.toCharArray();
if (caa.length != cab.length) {
return false;
} else {
byte ret = 0;
for (int i = 0; i < caa.length; ++i) {
ret = (byte) (ret | caa[i] ^ cab[i]);
}
return ret == 0;
}
}
passwordEncoder 보다가 equals 괜찮아보여서 긁어옴.
나중에 SW역량 B형 준비할 때 써먹어야쥐
Comments powered by Disqus.