Last active
December 31, 2015 18:49
-
-
Save CodingFabian/8029438 to your computer and use it in GitHub Desktop.
The most dreadful code I have seen in a while
This file contains 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 makeValid(String value) { | |
value = value.replaceAll("a", "A"); | |
value = value.replaceAll("b", "B"); | |
value = value.replaceAll("c", "C"); | |
value = value.replaceAll("d", "D"); | |
value = value.replaceAll("e", "E"); | |
value = value.replaceAll("f", "F"); | |
value = value.replaceAll("g", "G"); | |
value = value.replaceAll("h", "H"); | |
value = value.replaceAll("i", "I"); | |
value = value.replaceAll("j", "J"); | |
value = value.replaceAll("k", "K"); | |
value = value.replaceAll("l", "L"); | |
value = value.replaceAll("m", "M"); | |
value = value.replaceAll("n", "N"); | |
value = value.replaceAll("o", "O"); | |
value = value.replaceAll("p", "P"); | |
value = value.replaceAll("q", "Q"); | |
value = value.replaceAll("r", "R"); | |
value = value.replaceAll("s", "S"); | |
value = value.replaceAll("t", "T"); | |
value = value.replaceAll("u", "U"); | |
value = value.replaceAll("v", "V"); | |
value = value.replaceAll("w", "W"); | |
value = value.replaceAll("x", "X"); | |
value = value.replaceAll("y", "Y"); | |
value = value.replaceAll("z", "Z"); | |
value = value.replaceAll("ä", "Ä"); | |
value = value.replaceAll("ö", "Ö"); | |
value = value.replaceAll("ü", "Ü"); | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Christian, you are right, it is at least mostly O(n). But there is another detail hidden.
Hint: Look at the source of replaceAll, preferably in Java 1.6 which was used.
Hint2: The Strings created are not the heaviest objects involved.