dcsimg
how to create ReadOnly ArrayList?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   kalesha_shaik
Posted On:   Thursday, December 30, 2004 08:41 PM

how to create ReadOnly ArrayList?

Re: how to create ReadOnly ArrayList?

Posted By:   Anonymous  
Posted On:   Thursday, December 30, 2004 10:13 PM

Here's a sample code....

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ReadOnlyArrayList {

public static void main(String[] args) {
List readOnlyList = new ArrayList();
try {
readOnlyList.add("Value 1");
readOnlyList.add("Value 2");
System.out.println(readOnlyList);
readOnlyList = Collections.unmodifiableList(readOnlyList);
readOnlyList.add("Value 3");
} catch (UnsupportedOperationException e) {
e.printStackTrace();
System.out.println(readOnlyList);
}
}
}

Thanks!
About | Sitemap | Contact