Manipulating Lists and Collections

I recently came across a module in my application that uses collections and lists. And yes, it is in Java. So either for performance reasons, or because the author used the Lists, as well as maps in many places. He performs the usual operations on it, like deleting some elements, adding, updating the list, and every time he does it, he does it by looking at the entire list. Several times the lists are in the range of 10,000 items.

Now here is my question: why is there no language function that facilitates this operation? I mean, why can't we have some rudimentary SQL that can be executed in lists and collections? Is there any language that has such a function?

PS: Well, I'm not sure if this is a bit subjective and against SO rules. But I feel a strong desire to ask about it here. Maybe admins can fix it. So here.

+3
source share
6 answers

Along with Google collections, I recommend looking at LambdaJ :

List<Person> sortedByAgePersons = new ArrayList<Person>(persons);
Collections.sort(sortedByAgePersons, new Comparator<Person>() {
        public int compare(Person p1, Person p2) {
           return Integer.valueOf(p1.getAge()).compareTo(p2.getAge());
        }
});

becomes

List<Person> sortedByAgePersons = sort(persons, on(Person.class).getAge());

Lots of neat sorting, filtering, and list functions.

+6
source

There are some functional style methods in the Google Collection, especially in , and . Collections2 Iterables Maps

But due to the lack of closures or the compact syntax of the inner class in (pre-7) Java, using them can become quite verbose.

+4
source

, LambdaJ. , , . Java , . , , , . . Java, mobile sdk, Java , , , , , .

0

, List . , - , Multimap<String, Whatever>, . (Multimap Google.)

0

LINQ .NET , , Java.

-1

Java , . . , , Enumeration, , .

Java 1.2 . , .

, Groovy, , .

[EDIT] ArrayList, ( , , ).

-1

Source: https://habr.com/ru/post/1727750/


All Articles