public class StringBuilderSpeed {
public static final char ch[] = new char[]{'a','b','c','d','e','f','g','h','i'};
public static void main(String a[]){
int loopTime = 99999999;
long startTime = System.currentTimeMillis();
StringBuilder sb = new StringBuilder();
for(int i = 0 ; i < loopTime; i++){
for(char c : ch){
sb.append(c);
}
sb.setLength(0);
}
long endTime = System.currentTimeMillis();
System.out.println("Time cost: " + (endTime - startTime));
}
public static void clear(StringBuilder value) {
for (int i = 0, len = value.length(); i < len; i++) {
value.setCharAt(i, Character.MIN_VALUE);
}
value.setLength(0);
}
public static void main(String[] args) {
StringBuilder sb = new StringBuilder("clear this password");
// use & process sb
clear(sb);
}