Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

This is probably not your bottleneck, but you could achieve the same result by:

  • ditching the StringTokenizer in favour of String.split()
  • replacing the while loop with a call to Collections.addAll(T...)

Like so:

while ((currentLine = bufferedReader.readLine()) != null) {
 Collections.addAll(arrayList, currentLine.split(" ")));
}

The static method Collections.addAll() is preferable to arrayList.addAll(Arrays.asList()):

public static <T> boolean addAll(Collection<? super T> c, T... elements)

Adds all of the specified elements to the specified collection. Elements to be added may be specified individually or as an array. The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this method is likely to run significantly faster under most implementations.

This is probably not your bottleneck, but you could achieve the same result by:

  • ditching the StringTokenizer in favour of String.split()
  • replacing the while loop with a call to Collections.addAll(T...)

Like so:

while ((currentLine = bufferedReader.readLine()) != null) {
 Collections.addAll(arrayList, currentLine.split(" ")));
}

The static method Collections.addAll() is preferable to arrayList.addAll(Arrays.asList()):

public static <T> boolean addAll(Collection<? super T> c, T... elements)

Adds all of the specified elements to the specified collection. Elements to be added may be specified individually or as an array. The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this method is likely to run significantly faster under most implementations.

This is probably not your bottleneck, but you could achieve the same result by:

  • ditching the StringTokenizer in favour of String.split()
  • replacing the while loop with a call to Collections.addAll(T...)

Like so:

while ((currentLine = bufferedReader.readLine()) != null) {
 Collections.addAll(arrayList, currentLine.split(" ")));
}

The static method Collections.addAll() is preferable to arrayList.addAll(Arrays.asList()):

public static <T> boolean addAll(Collection<? super T> c, T... elements)

Adds all of the specified elements to the specified collection. Elements to be added may be specified individually or as an array. The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this method is likely to run significantly faster under most implementations.

changed to a better-performing method
Source Link
Adam
  • 5.2k
  • 1
  • 30
  • 47

This is probably not your bottleneck, but you could achieve the same result by:

  • ditching the StringTokenizer in favour of String.split()
  • replacing the while loop with a call to ArrayList<T>Collections.addAll(T...)

Like so:

while ((currentLine = bufferedReader.readLine()) != null) {
 arrayListCollections.addAll(Arrays.asList(arrayList, currentLine.split(" ")));
}

The static method Collections.addAll() is preferable to arrayList.addAll(Arrays.asList()):

public static <T> boolean addAll(Collection<? super T> c, T... elements)

Adds all of the specified elements to the specified collection. Elements to be added may be specified individually or as an array. The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this method is likely to run significantly faster under most implementations.

This is probably not your bottleneck, but you could achieve the same result by:

  • ditching the StringTokenizer in favour of String.split()
  • replacing the while loop with a call to ArrayList<T>.addAll()

Like so:

while ((currentLine = bufferedReader.readLine()) != null) {
 arrayList.addAll(Arrays.asList(currentLine.split(" ")));
}

This is probably not your bottleneck, but you could achieve the same result by:

  • ditching the StringTokenizer in favour of String.split()
  • replacing the while loop with a call to Collections.addAll(T...)

Like so:

while ((currentLine = bufferedReader.readLine()) != null) {
 Collections.addAll(arrayList, currentLine.split(" ")));
}

The static method Collections.addAll() is preferable to arrayList.addAll(Arrays.asList()):

public static <T> boolean addAll(Collection<? super T> c, T... elements)

Adds all of the specified elements to the specified collection. Elements to be added may be specified individually or as an array. The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this method is likely to run significantly faster under most implementations.

Source Link
Adam
  • 5.2k
  • 1
  • 30
  • 47

This is probably not your bottleneck, but you could achieve the same result by:

  • ditching the StringTokenizer in favour of String.split()
  • replacing the while loop with a call to ArrayList<T>.addAll()

Like so:

while ((currentLine = bufferedReader.readLine()) != null) {
 arrayList.addAll(Arrays.asList(currentLine.split(" ")));
}
lang-java

AltStyle によって変換されたページ (->オリジナル) /