StringUtilities.java 732B

123456789101112131415161718192021222324
  1. public class StringUtilities {
  2. public Character getMiddleCharacter(String word){
  3. int middleVal = (word.length() / 2);
  4. return word.charAt(middleVal);
  5. }
  6. public String removeCharacter(String value, char charToRemove){
  7. // remove the characters in the string using replace with ""
  8. String newString = value.replace(Character.toString(charToRemove), "");
  9. return newString;
  10. }
  11. public String getLastWord(String value) {
  12. // return the last word of the string
  13. // use split and return the last word of the array
  14. String words = "";
  15. String[] famousLastWords = value.split(" ");
  16. return famousLastWords[famousLastWords.length -1];
  17. }
  18. }