StringUtilities.java 860B

12345678910111213141516171819202122232425262728
  1. public class StringUtilities {
  2. public Character getMiddleCharacter(String word){
  3. int middleIndex = word.length() / 2;
  4. char middleCharacter = word.charAt(middleIndex);
  5. return middleCharacter;
  6. }
  7. public String removeCharacter(String value, char charToRemove){
  8. StringBuilder sb = new StringBuilder(value);
  9. while(sb.toString().indexOf(charToRemove) != -1) {
  10. sb = sb.deleteCharAt(sb.toString().indexOf(charToRemove));
  11. }
  12. return sb.toString();
  13. }
  14. public String getLastWord(String value) {
  15. String lastWord = "";
  16. for(int i = value.length() - 1; i > 0; i--) {
  17. if(Character.isWhitespace(value.charAt(i))) {
  18. lastWord = value.substring(i + 1, value.length());
  19. break;
  20. }
  21. }
  22. return lastWord;
  23. }
  24. }