-
Notifications
You must be signed in to change notification settings - Fork 2
/
StringArrayUtils.java
57 lines (52 loc) · 1.59 KB
/
StringArrayUtils.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package io.github.ackuq;
import java.util.Arrays;
/**
* A class that provides simple utility functions that can be used on string
* arrays.
*/
public class StringArrayUtils {
/**
* Trim each element in the array
*
* @param array An array of values to be trimmed
* @return The resulting array
*/
public static String[] trim(String[] array) {
return Arrays.stream(array)
.map(s -> s != null ? s.trim() : null)
.toArray(String[]::new);
}
/**
* Capitalize each element in the array
*
* @param array An array of values to be capitalized
* @return The resulting array
*/
public static String[] capitalize(String[] array) {
return Arrays.stream(array)
.map(s -> s !=null ? s.substring(0, 1).toUpperCase() + s.substring(1) : null)
.toArray(String[]::new);
}
/**
* Transforms the strings in the array to be lowercase
*
* @param array An array of values which should be transformed
* @return The resulting array
*/
public static String[] toLowerCase(String[] array) {
return Arrays.stream(array)
.map(s -> s != null ? s.toLowerCase() : null)
.toArray(String[]::new);
}
/**
* Transforms the strings in the array to be uppercase
*
* @param array An array of values which should be transformed
* @return The resulting array
*/
public static String[] toUpperCase(String[] array) {
return Arrays.stream(array)
.map(s -> s != null ? s.toUpperCase() : null)
.toArray(String[]::new);
}
}