12345678910111213141516171819202122232425262728293031
  1. public class StringUtilities {
  2. public Character getMiddleCharacter(String word){
  3. int post;
  4. int leng;
  5. if (word.length()% 2 == 1){
  6. post=word.length()/2;
  7. leng= 1;
  8. } else {
  9. post=word.length()/2-1;
  10. leng = 1;
  11. }
  12. String mid = word.substring(post, post
  13. + leng);
  14. char output = mid.charAt(0);
  15. return output;
  16. }
  17. public String removeCharacter(String value, char charToRemove){
  18. String newString = value.replaceAll(Character.toString(charToRemove), "");
  19. return newString;
  20. }
  21. public String getLastWord(String value) {
  22. String lastWord = value.substring(value.lastIndexOf(" ")+1);
  23. return lastWord;
  24. }
  25. }