Trying to use the following to add to the front of a List but throws on the add. The doc says it's supposed to shift. What is the fix or workaround?
List<String> whatever = Arrays.asList("Blah1", "Blah2");
whatever.add(0, "BlahAll"); // <- Throws
You can't add element to a list created using Arrays.asList()
. As the documentation explains:
Returns a fixed-size list backed by the specified array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With