Collection of empty judgment operation

IF ( null == || list.size List () == 0 ) { 
 
  // empty case 
 
} the else { 
 
  // not empty cases 
 
}

If you want to determine whether the list is empty, so to determine:

but,

list.isEmpty () and list.size () == 0 so what difference does it make?

Answer: no difference.

      isEmpty () determines there is no element, while the size () Returns a few elements,

      If it is judged whether or element of a set of suggested isEmpty () method. The next logical usage.

list! = Null now! list.isEmpty () What is the difference?

This is comparable to, you want to drink,
      the front is the judge is not even the cups are not,
      the back of the cup is to determine there is no water,
      and even things are not filled with water,
      this water come from?
      Therefore, the determination is generally
      

      if (list! = null &&! list.isEmpty ()) {
        this which takes a value in the list
      } else {
        do other processing
      }

Guess you like

Origin www.cnblogs.com/qingmuchuanqi48/p/11565859.html