Hi everyone, Is there a reasonable explanation, why searching an element in Java collection is so hard? For example, let's say I have:
ArrayList<People> listPeople = new ArrayList<People>();
public class People
{
public String name;
public String age;
//some other code here
}
You got the idea ... Now, if I want to get from list a Person with given name, let's say 'Anthares' I have to do so much work: Create a new Person with name 'Anthares', probably initiate it with some other data, predefine my equals method for Person class, then call listPeople.IndexOf(tempPerson) and finally get the returned int and make listPeople[idx]
Why is all this pain. For example, in C# I can make a linq expression, pass it to the proper method of my collection and that's it. One simple line of code.