diff --git a/src/main/java/org/apache/commons/lang3/CharSet.java b/src/main/java/org/apache/commons/lang3/CharSet.java index 3fdfd07d8..795511553 100644 --- a/src/main/java/org/apache/commons/lang3/CharSet.java +++ b/src/main/java/org/apache/commons/lang3/CharSet.java @@ -225,7 +225,7 @@ public class CharSet implements Serializable { // NOTE: This is no longer public as CharRange is no longer a public class. // It may be replaced when CharSet moves to Range. /*public*/ CharRange[] getCharRanges() { - return set.toArray(new CharRange[set.size()]); + return set.toArray(new CharRange[0]); } //----------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index abde7ec26..d6298062c 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -7507,7 +7507,7 @@ public class StringUtils { currentType = type; } list.add(new String(c, tokenStart, c.length - tokenStart)); - return list.toArray(new String[list.size()]); + return list.toArray(new String[0]); } /** @@ -7735,7 +7735,7 @@ public class StringUtils { } } - return substrings.toArray(new String[substrings.size()]); + return substrings.toArray(new String[0]); } // ----------------------------------------------------------------------- @@ -7923,7 +7923,7 @@ public class StringUtils { if (match || preserveAllTokens && lastMatch) { list.add(str.substring(start, i)); } - return list.toArray(new String[list.size()]); + return list.toArray(new String[0]); } /** @@ -8022,7 +8022,7 @@ public class StringUtils { if (match || preserveAllTokens && lastMatch) { list.add(str.substring(start, i)); } - return list.toArray(new String[list.size()]); + return list.toArray(new String[0]); } /** @@ -8835,7 +8835,7 @@ public class StringUtils { if (list.isEmpty()) { return null; } - return list.toArray(new String[list.size()]); + return list.toArray(new String[0]); } /** diff --git a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java index 596961412..dd154e312 100644 --- a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java +++ b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java @@ -274,7 +274,7 @@ public class ExceptionUtils { } frames.addAll(trace); } - return frames.toArray(new String[frames.size()]); + return frames.toArray(new String[0]); } /** @@ -325,7 +325,7 @@ public class ExceptionUtils { while (frames.hasMoreTokens()) { list.add(frames.nextToken()); } - return list.toArray(new String[list.size()]); + return list.toArray(new String[0]); } /** @@ -438,7 +438,7 @@ public class ExceptionUtils { */ public static Throwable[] getThrowables(final Throwable throwable) { final List list = getThrowableList(throwable); - return list.toArray(new Throwable[list.size()]); + return list.toArray(new Throwable[0]); } /** diff --git a/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java b/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java index d72dc5380..553be4e5b 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java @@ -199,7 +199,7 @@ public class FieldUtils { */ public static Field[] getAllFields(final Class cls) { final List allFieldsList = getAllFieldsList(cls); - return allFieldsList.toArray(new Field[allFieldsList.size()]); + return allFieldsList.toArray(new Field[0]); } /** @@ -237,7 +237,7 @@ public class FieldUtils { */ public static Field[] getFieldsWithAnnotation(final Class cls, final Class annotationCls) { final List annotatedFieldsList = getFieldsListWithAnnotation(cls, annotationCls); - return annotatedFieldsList.toArray(new Field[annotatedFieldsList.size()]); + return annotatedFieldsList.toArray(new Field[0]); } /** diff --git a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java index bbd5019fe..491470d68 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java @@ -878,7 +878,7 @@ public class MethodUtils { final boolean searchSupers, final boolean ignoreAccess) { final List annotatedMethodsList = getMethodsListWithAnnotation(cls, annotationCls, searchSupers, ignoreAccess); - return annotatedMethodsList.toArray(new Method[annotatedMethodsList.size()]); + return annotatedMethodsList.toArray(new Method[0]); } /** diff --git a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java index 2a6ccd00a..f9df8c63a 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java @@ -1149,7 +1149,7 @@ public class TypeUtils { } } - return types.toArray(new Type[types.size()]); + return types.toArray(new Type[0]); } /** diff --git a/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java b/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java index c9ab66616..97fae7d78 100644 --- a/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java +++ b/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java @@ -604,10 +604,10 @@ public class StrTokenizer implements ListIterator, Cloneable { if (chars == null) { // still call tokenize as subclass may do some work final List split = tokenize(null, 0, 0); - tokens = split.toArray(new String[split.size()]); + tokens = split.toArray(new String[0]); } else { final List split = tokenize(chars, 0, chars.length); - tokens = split.toArray(new String[split.size()]); + tokens = split.toArray(new String[0]); } } } diff --git a/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java b/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java index 83af2e0ae..4a7523790 100644 --- a/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java +++ b/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java @@ -564,7 +564,7 @@ public class DurationFormatUtils { if (inLiteral) { // i.e. we have not found the end of the literal throw new IllegalArgumentException("Unmatched quote in format: " + format); } - return list.toArray(new Token[list.size()]); + return list.toArray(new Token[0]); } //----------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java b/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java index a5edb289e..888d3fb60 100644 --- a/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java +++ b/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java @@ -160,7 +160,7 @@ public class FastDatePrinter implements DatePrinter, Serializable { */ private void init() { final List rulesList = parsePattern(); - mRules = rulesList.toArray(new Rule[rulesList.size()]); + mRules = rulesList.toArray(new Rule[0]); int len = 0; for (int i=mRules.length; --i >= 0; ) { diff --git a/src/test/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java b/src/test/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java index b3fb5cfab..2819006b2 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java @@ -407,7 +407,7 @@ public class EventCountCircuitBreakerTest { */ public void verify(final Boolean... values) { assertArrayEquals(values, - changedValues.toArray(new Boolean[changedValues.size()])); + changedValues.toArray(new Boolean[0])); } } }