I have a class that is extending Java\'s ArrayList. I\'m currently using Java build 1.6.0_22-b04. Looks like this:
public class TokenSequence extends ArrayList&
create a custom ArrayList class and override the add the method as follows
public class CustomArrayList extends ArrayList{
@Override
public boolean add(E e) {
String temp = (String)e;
if(temp==null || temp.isEmpty()){
return false;
}
return super.add(e);
}
}
with this class, following example will add only 1 element and print size as 1
public static void main(String args[]) {
ArrayList lst = new CustomArrayList();
lst.add("aaaa");
lst.add(null);
lst.add("");
System.out.println(lst.size());
}