1. 程式人生 > >ArrayList的add()方法使用

ArrayList的add()方法使用

You could create your own ArrayList-Class (derived from the original) and override the Add-Method
Then you could check for null when Adding.

publicbooleanAdd(E e){if(e ==null)returnfalse;elsereturnsuper.Add(e)}

As Mark stated in the comments you perhaps want to override all other possibilties of Adding values too. (

see the doc)

  • add(E e)
  • add(int index, E element)
  • addAll(Collection c)
  • addAll(int index, Collection c)
  • set(int index, E element)