0% found this document useful (0 votes)
15 views1 page

Java String Utility Functions

The document contains a Java class named 'strfun1' that provides various string manipulation methods. These methods include reversing a string, checking for palindromes, converting to uppercase, concatenating two strings, checking for a substring, and trimming whitespace. Each method includes input validation to ensure that null strings are not processed.

Uploaded by

vincent2112.mv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

Java String Utility Functions

The document contains a Java class named 'strfun1' that provides various string manipulation methods. These methods include reversing a string, checking for palindromes, converting to uppercase, concatenating two strings, checking for a substring, and trimming whitespace. Each method includes input validation to ensure that null strings are not processed.

Uploaded by

vincent2112.mv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

package strfun;

public class strfun1 {

public static String reverseString(String input) {


if (input == null) {
throw new IllegalArgumentException("Input string cannot be null");
}
StringBuilder reversed = new StringBuilder(input);
return [Link]().toString();
}

public static boolean isPalindrome(String input) {


if (input == null) {
throw new IllegalArgumentException("Input string cannot be null");
}
String reversed = reverseString(input);
return [Link](reversed);
}

public static String toUpperCase(String input) {


if (input == null) {
throw new IllegalArgumentException("Input string cannot be null");
}
return [Link]();
}

public static String concatenate(String str1, String str2) {


if (str1 == null || str2 == null) {
throw new IllegalArgumentException("Neither string can be null");
}
return str1 + str2;
}

public static boolean containsSubstring(String str, String substring) {


if (str == null || substring == null) {
throw new IllegalArgumentException("Neither string can be null");
}
return [Link](substring);
}

public static String trimWhitespace(String str) {


if (str == null) {
throw new IllegalArgumentException("Input string cannot be null");
}
return [Link]();
}
}

You might also like