12345678910111213141516171819202122232425262728 |
- public class StringUtilities {
- public Character getMiddleCharacter(String word){
- int middleIndex = word.length() / 2;
- char middleCharacter = word.charAt(middleIndex);
- return middleCharacter;
- }
-
- public String removeCharacter(String value, char charToRemove){
- StringBuilder sb = new StringBuilder(value);
-
- while(sb.toString().indexOf(charToRemove) != -1) {
- sb = sb.deleteCharAt(sb.toString().indexOf(charToRemove));
- }
- return sb.toString();
- }
-
- public String getLastWord(String value) {
- String lastWord = "";
- for(int i = value.length() - 1; i > 0; i--) {
- if(Character.isWhitespace(value.charAt(i))) {
- lastWord = value.substring(i + 1, value.length());
- break;
- }
- }
- return lastWord;
- }
- }
|