I’m trying to write a method that will return the larger of the two arrays.
List<String> firstName = new ArrayList<String>(); // size 50
List<String> lastName = new ArrayList<String>(); // size 1000
I want to compare their size and return a larger array. Something like this.
public List<String> largerArray (List firstName, List lastName) {
return max.size(firstName, lastName);
}
>Solution :
public List<String> largerArray (List firstName, List lastName) {
return firstName.size() > lastName.size() ? firstName : lastName;
}
Although your use case is not very clear. If firstName is a list then ideally it must be named as firstNames, if its not the case then i am not sure what exactly you’re trying to do there