Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thospfuller/62784623e8f89072f652ec0d60e010f0 to your computer and use it in GitHub Desktop.
Save thospfuller/62784623e8f89072f652ec0d60e010f0 to your computer and use it in GitHub Desktop.
Example One: How to turn an array into an ArrayList in Java using the addAll method (without the need to autobox).
@Grab(group='com.jamonapi', module='jamon', version='2.82')
import com.jamonapi.Monitor
import com.jamonapi.MonitorFactory
import static java.util.Arrays.asList
import java.util.stream.Collectors;
import java.util.List;
import java.util.Arrays;
import java.util.Random
def random = new Random()
def arrayCapacity = 10000
def numbers = new java.lang.Integer[arrayCapacity + 1]
for (int ctr in 0..arrayCapacity) {
numbers[ctr] = java.lang.Integer.valueOf(random.nextInt())
}
def iterations = 100000
def monitor = MonitorFactory.start("Convert an array to an ArrayList performance monitor via the addAll method example")
for (ctr in 0..iterations) {
def tempResult = asList (numbers)
def result = new java.util.ArrayList (arrayCapacity) as java.util.List
result.addAll (tempResult)
}
monitor.stop ()
println "iterations: $iterations, performance: $monitor"
return;
@thospfuller
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment