Sorry for such a vague title. Did not think of good one.
Situation:
- Have a List of User objects.
- Need to create array for UserInfo object.
- UserInfo object is created is based on information in User object. (Currently has a method for this)
Which is better in such a situation?
- Should I pass whole list of User to User to UserInfo conversion method.
- or Should I loop over list of User and pass each user object to conversion method 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 first approach we pass a big object(list of User) as an argument and in second we call same method multiple times.Which is better?
The size of User list will be range from 25-200 objects in it.