Skip to content

Instantly share code, notes, and snippets.

@leonardreidy
Last active October 8, 2016 20:31
Show Gist options
  • Save leonardreidy/66bb40184e8ee8bea35b to your computer and use it in GitHub Desktop.
Save leonardreidy/66bb40184e8ee8bea35b to your computer and use it in GitHub Desktop.
Simple Java class containing methods for performing common actions on Strings.
public class StringUtilities
{
/**
* Check if input string is a vowel
* Author: http://stackoverflow.com/users/1357341/arshajii
**/
public static boolean isVowel(String inStr)
{
return "aeiou".indexOf(inStr.toLowerCase()) >= 0;
}
/**
* Check if input string is a consonant
* Author: http://stackoverflow.com/users/1357341/arshajii
**/
public static boolean isConsonant(String inStr)
{
return "bcdfghjklmnpqrstvwxyz".indexOf(inStr.toLowerCase()) >= 0;
}
/** Given a String array containing words,
* join the elements of the array with the
* given separator and return to caller
* Author: http://stackoverflow.com/users/4108825/ivanp
**/
public static String join(String[] strArr, String separator)
{
String returnVal = "";
for(String s: strArr){ returnVal += separator + s; }
return returnVal.replaceFirst(separator, "");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment