Skip to content

Commit 5460eef

Browse files
committed
Update StringUtils.java
1 parent 61fe723 commit 5460eef

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/main/java/io/github/intisy/utils/utils/StringUtils.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static String encrypt(String password) {
7777
throw new RuntimeException(e);
7878
}
7979
}
80-
80+
8181
public static List<String> splitString(String string) {
8282
List<String> result = new ArrayList<>();
8383
StringBuilder line = new StringBuilder();
@@ -96,4 +96,25 @@ public static List<String> splitString(String string) {
9696
}
9797
return result;
9898
}
99+
100+
public static String toTitleCase(String input) {
101+
if (input == null || input.isEmpty()) {
102+
return input;
103+
}
104+
105+
String[] words = input.split(" ");
106+
StringBuilder titleCase = new StringBuilder();
107+
108+
for (String word : words) {
109+
if (word.length() > 1) {
110+
titleCase.append(Character.toUpperCase(word.charAt(0)))
111+
.append(word.substring(1).toLowerCase());
112+
} else {
113+
titleCase.append(word.toUpperCase());
114+
}
115+
titleCase.append(" ");
116+
}
117+
118+
return titleCase.toString().trim();
119+
}
99120
}

0 commit comments

Comments
 (0)