문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top