PoweredByApartium / cocoa-beans

General purpose library for Java & Spigot
MIT License
4 stars 0 forks source link

Create function that help you add element to sorted list #79

Closed ikfir closed 3 weeks ago

ikfir commented 3 weeks ago

Should be called addElementSorted The function should take List<E> E Comparator<E>

Example of usage

        List<Integer> list = new ArrayList<>();
        Comparator<Integer> comparator = Integer::compare;

        CollectionHelpers.addElementSorted(list, 1, comparator);
        CollectionHelpers.addElementSorted(list, 7, comparator);
        CollectionHelpers.addElementSorted(list, 9, comparator);
        CollectionHelpers.addElementSorted(list, 2, comparator);

        // List [1, 2, 7, 9]
ikfir commented 3 weeks ago

Closed by #77 where I added it