Skip to content

Commit

Permalink
library: optimize Collection.toArray() usage
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jun 22, 2024
1 parent 3c05e5c commit a6f0ba0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
3 changes: 1 addition & 2 deletions HeartLibrary/src/main/java/jme3utilities/Heart.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ public static Map<String, File> driveMap() {
public static <T> T first(Collection<T> collection) {
T result = null;
if (!collection.isEmpty()) {
int size = collection.size();
Object[] members = collection.toArray(new Object[size]);
Object[] members = collection.toArray(new Object[0]);
result = (T) members[0];
}

Expand Down
5 changes: 1 addition & 4 deletions HeartLibrary/src/main/java/jme3utilities/MyString.java
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,7 @@ public static int sharedPrefixLength(CharSequence s1, CharSequence s2) {
* @return a new array containing the same strings in the same order
*/
public static String[] toArray(Collection<String> collection) {
int count = collection.size();
String[] array = new String[count];
collection.toArray(array);

String[] array = collection.toArray(new String[0]);
return array;
}

Expand Down

0 comments on commit a6f0ba0

Please sign in to comment.