Question

For a class assignment I have to compare different lists' performance with one another's using UUID.randomUUID().toString() to insert a few thousand random strings in a list and record how long it takes with the nanoTime() method. I just can't recall how to set the amount of calls to my add method for my list to a certain number, or how to do it with the UUID.randomUUID(), at least.

newbieList.add(UUID.randomUUID().toString());

is what I have, which just inserts one random string, of course.

I know this is a simple question probably but I couldn't find any answers Googling or here, so help would be appreciated! Thanks.

Was it helpful?

Solution

Just put it in a for loop. A for loop is used for repeating stuff when you know at the beginning how often you want to repeat.

See this answer to a related question for lots of examples for various for loops.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top