private final List<Character> chars;
- public String2(final String value) {
+ public String2(String value) {
+ if (value == null)
+ value = "";
+
chars = new ArrayList<>(value.length());
for (final Character c : value.toCharArray())
chars.add(c);
}
public String2 addPrefix(final String prefix) {
+ if (prefix == null)
+ return this;
+
int i = 0;
for (final char c : prefix.toCharArray())
chars.add(i++, c);
}
public String2 addSuffix(final String suffix) {
+ if (suffix == null)
+ return this;
+
for (final char c : suffix.toCharArray())
chars.add(c);
}
public String2 trimPrefixIfExists(String prefix){
+ if (prefix == null)
+ return this;
+
if (hasPrefix(prefix))
trimPrefix(prefix.length());