I've a list of user object. And I want to get list of user name except using loop. Is there any collection or util function in java 7??
-
1what is the problem with for loopshreyansh jogi– shreyansh jogi2013-11-18 10:44:13 +00:00Commented Nov 18, 2013 at 10:44
-
1@Rounak: there is no way to do that without a loop. Whatever library you find, it will always use a loop. What is "huge"?JB Nizet– JB Nizet2013-11-18 10:45:58 +00:00Commented Nov 18, 2013 at 10:45
-
1@JBNizet There is a way to do it without a loop, by creating a view into the underlying User list. Maybe Guava has something like that? Whether that would solve OP's performance issue highly depends on his access pattern of the name list.Marko Topolnik– Marko Topolnik2013-11-18 10:50:50 +00:00Commented Nov 18, 2013 at 10:50
-
15,000 users is not a huge list.Marko Topolnik– Marko Topolnik2013-11-18 10:56:39 +00:00Commented Nov 18, 2013 at 10:56
-
2@Rounak 5000 items in a List is a ridiculously small number. There's no performance issues involved here, trust me.Kayaman– Kayaman2013-11-18 10:56:43 +00:00Commented Nov 18, 2013 at 10:56
|
Show 5 more comments
2 Answers
No, there's no util function. It's 3 lines of code to do it yourself.
Even if there was a util function, it wouldn't help with performance. It would be implemented as a for loop.
As for performance, have you actually profiled your application and seen that iterating the List is a performance hotspot?