-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlternateCase.java
32 lines (26 loc) · 925 Bytes
/
AlternateCase.java
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
package com.smlnskgmail.jaman.codewarsjava.kyu7;
import java.util.stream.Collectors;
// https://www.codewars.com/kata/57a62154cf1fa5b25200031e
public class AlternateCase {
private final String input;
public AlternateCase(String input) {
this.input = input;
}
// CPD-OFF
public String solution() {
return input
.chars()
.mapToObj(i -> {
char symbol = (char) i;
if (!Character.isLetter(symbol)) {
return String.valueOf((char) i);
}
return String.valueOf(
Character.isLowerCase(symbol)
? Character.toUpperCase(symbol)
: Character.toLowerCase(symbol)
);
})
.collect(Collectors.joining(""));
}
}