Using unmodifiable list Java 9

package test;package test;
import java.util.Collections;import java.util.Iterator;import java.util.List;
public class listtest {
public static void main(String[] args) { // TODO Auto-generated method stub
List im=List.of(“one”,”two”,”three”); List imlist=Collections.unmodifiableList(im); imlist.add(“four”); Iterator itr=imlist.iterator(); while(itr.hasNext()) { System.out.println(; } }

In this case if you try to add new number in list this will result in java.lang.UnsupportedOperationException


About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Java, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s