Sorry for such an uncertain title. I did not think about the good.
Situation:
- Have a list of user objects.
- You must create an array for the UserInfo object.
- The UserInfo object is created based on the information in the User object. (There is currently a method for this)
What is better in this situation?
- Should I pass a complete list of User to User to UserInfo methods.
- or I need to iterate over the list of users and pass the conversion method to each user object and get UserInfo for it.
Examples:
List<User> users = .....; UserInfo[] userInfos = getUserInfoFromUser(users); //(conversion method will loop and generate array, then return it.)
or
List<User> users = .....; UserInfo[] userInfos = new UserInfo[users.size()] for (int j = 0; j < users.size(); j++) { userInfos[j] = getUserInfoFromUser(users.get(j)); }
In the first approach, we pass a large object (a list of users) as an argument, and in the second we call the same method several times. What's better?
The size of the user list will vary from 25-200 objects.
source share