Created
February 13, 2013 16:52
-
-
Save charlespunk/4946039 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ _ _ I t _ _ _ _ i s _ _ a _ a p p l e _ _ => I t _ i s _ a _ a p p l e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String removeSpaces(String input){ | |
boolean seenGood = false; | |
boolean seenSpace = false; | |
StringBuffer sb = new StringBuffer(); | |
for(int i = 0; i < input.size(); i++){ | |
if(input.charAt(i) == " ") seenSpace = true; | |
else{ | |
if(seenGood && seenSpace){ | |
sb.add(" "); | |
seenSpace = false; | |
} | |
sb.add(input.charAt(i)); | |
seenGood = true; | |
} | |
} | |
return sb.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment