Skip to content

Commit ab544c3

Browse files
acbinyanglbme
andauthored
Fix Null Pointer Exception in strings/Upper (TheAlgorithms#3005)
Co-authored-by: Yang Libin <contact@yanglibin.info>
1 parent e7ff986 commit ab544c3

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/main/java/com/thealgorithms/strings/Upper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public static void main(String[] args) {
1919
* @return the {@code String}, converted to uppercase.
2020
*/
2121
public static String toUpperCase(String s) {
22+
if (s == null || "".equals(s)) {
23+
return s;
24+
}
2225
char[] values = s.toCharArray();
2326
for (int i = 0; i < values.length; ++i) {
2427
if (Character.isLetter(values[i]) && Character.isLowerCase(values[i])) {

0 commit comments

Comments
 (0)