View RSS Feed

My Java Tips

AbstractList

Rate this Entry
by , 11-03-2011 at 12:10 PM (888 Views)
AbstractList implements Collection and List interfaces. ArrayList, Vector and AbstractSequentialList extends from AbstractList. Actually AbstractList contains implementation of List interface for random access.



If you want to create a list that should not be modified, then you should extend this class. But then you have to provide implementations for the get(int index) and size() methods.

Java Code:
public class MyList extends AbstractList {

	@Override
	public Object get(int arg0) {
		return null;
	}

	@Override
	public int size() {
		return 0;
	}
}
If you want a list to be modifiable, then you must additionally override set(int index, Object element) method.

Submit "AbstractList" to Facebook Submit "AbstractList" to Digg Submit "AbstractList" to del.icio.us Submit "AbstractList" to StumbleUpon Submit "AbstractList" to Google

Tags: None Add / Edit Tags
Categories
Java SE

Comments