-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
47 lines (31 loc) · 944 Bytes
/
Copy pathSolution.java
File metadata and controls
47 lines (31 loc) · 944 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package java8.StringOperations;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Solution {
public boolean arrayStringsAreEqual3(String[] word1, String[] word2) {
return Stream.of(word1).collect(Collectors.joining()).equals(Stream.of(word2).collect(Collectors.joining()));
}
public boolean arrayStringsAreEqual2(String[] word1, String[] word2) {
Stream<String> w1 = Stream.of(word1);
String s1 = w1.collect(Collectors.joining());
Stream<String> w2 = Stream.of(word2);
String s2 = w2.collect(Collectors.joining());
if (s1.equals(s2))
return true;
return false;
}
public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
for (String s : word1) {
sb1.append(s);
}
for (String s : word2) {
sb2.append(s);
}
if (sb1.equals(sb2)) {
return true;
}
return false;
}
}