简体   繁体   中英

Using UUID.randomUUID() and calling method multiple times?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM