Skip navigation

If you want a fixed size list, wherein you don’t want to add/remove elements into it then probably this trick will save some line of code:

Consider this:

List<Character> vowels = new ArrayList<Character>();
vowels.add('a');
vowels.add('e');
vowels.add('i');
vowels.add('o');
vowels.add('u');


This could have also be written as:


 List<Character> vowels = Arrays.asList('a', 'e', 'i', 'o', 'u');

Trying to add/remove elements from this list will result in an UnsupportedOperationException exception

Leave a Reply

Your email address will not be published. Required fields are marked *

*


five + = 10

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>