StringUtilities.java 587B

123456789101112131415161718192021
  1. public class StringUtilities {
  2. public Character getMiddleCharacter(String word){
  3. if ((word.length() % 2) == 0) {
  4. return word.charAt(((word.length()/2)));
  5. } else return word.charAt((word.length()/2));
  6. }
  7. public String removeCharacter(String value, char charToRemove){
  8. String s = "";
  9. s = s + charToRemove;
  10. String str = "";
  11. str = value.replaceAll(s,"");
  12. return str;
  13. }
  14. public String getLastWord(String value) {
  15. String lastWord = value.substring(value.lastIndexOf(" ")+1);
  16. return lastWord;
  17. }
  18. }