I was having problems doing operations on a java.util.List object returned by Arrays.asList() method call. The specific exception was a java.lang.UnsupportedOperationException. I soon found out why this was a problem.
I like to use Arrays.asList as a nice one-line List creation tool. But, it turns out that many operations, such as add() and remove() are unusable on the List that is returned. The List returned is actually of type java.util.Arrays$ArrayList, a private static inner class of Arrays.
I was seeing this stack trace:
1 2 3 4
So, if removals are something you want to do, this won’t work:
Instead, you’ll have to resort to the old-fashioned multi-liner:
1 2 3 4
I guess if you want flexible lists, you’ll have to use Python after all.