privatestaticvoid checkCapacity(int before, int after) { if (before != after) { thrownew RuntimeException("capacity is expected to be unchanged: " + "before=" + before + " after=" + after);
}
}
privatestaticvoid testStringBuilder() {
StringBuilder sb = new StringBuilder("abc"); int cap = sb.capacity();
// test if negative minimumCapacity
sb.ensureCapacity(Integer.MIN_VALUE);
checkCapacity(cap, sb.capacity());
try { char[] str = {'a', 'b', 'c', 'd'}; // test if negative length
sb.append(str, 0, Integer.MIN_VALUE + 10); thrownew RuntimeException("IndexOutOfBoundsException not thrown");
} catch (IndexOutOfBoundsException ex) {
}
}
privatestaticvoid testStringBuffer() {
StringBuffer sb = new StringBuffer("abc"); int cap = sb.capacity();
// test if negative minimumCapacity
sb.ensureCapacity(Integer.MIN_VALUE);
checkCapacity(cap, sb.capacity());
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.