Why does collections.sort throw unsupported operation exception while sorting by comparator in Java?

The list is not modifiable, obviously your client method is creating an unmodifiable list (using e.g. Collections#unmodifiableList etc.). Simply create a modifiable list before sorting: List<String> modifiableList = new ArrayList<String>(unmodifiableList); Collections.sort(modifiableList, comparator);

Java Collections (LIFO Structure)

There’s actually a Stack class: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Stack.html If you don’t want to use that, the LinkedList class (http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedList.html) has addFirst and addLast and removeFirst and removeLast methods, making it perfect for use as a stack or queue class.

How to search in a List of Java object

You can give a try to Apache Commons Collections. There is a class CollectionUtils that allows you to select or filter items by custom Predicate. Your code would be like this: Predicate condition = new Predicate() { boolean evaluate(Object sample) { return ((Sample)sample).value3.equals(“three”); } }; List result = CollectionUtils.select( list, condition ); Update: In java8, … Read more

Map.of() vs. Collections.emptyMap()

Yes, there are even behavioral and not just technical differences between the collections returned by the emptyXyz factory methods in the Collections class and the new of factory methods introduced in the interfaces (Map, List, Set) with JDK 9, if these are invoked with no arguments. The relevant difference is that the collections returned by … Read more

Get first element of a collection that matches iterator function

You can use find: Looks through each value in the list, returning the first one that passes a truth test (iterator), or undefined if no value passes the test. The function returns as soon as it finds an acceptable element, and doesn’t traverse the entire list. Using your example: var g = _.find(arr, function (x) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)