Answers for "java list empty"

1

check list for empty and null java

/* 
	If you use the Apache Commons Collections library in your project, 
	you may use 
*/
CollectionUtils.isEmpty(MyList) or MapUtils.isEmpty(MyList) 

/* 
	which respectively check 
	if a collection or a map is empty or null 
	(i.e. they are "null-safe"). 
*/

/*
 Small tip:
 remember that the less code you write, 
 the less code you need to test as the complexity of your code decreases.
*/
Posted by: Guest on September-07-2021
0

ArrayList isEmpty() method in java

import java.util.ArrayList;
public class ArrayListIsEmptyMethodExample
{
   public static void main(String[] args)
   {
      ArrayList<Integer> al = new ArrayList<Integer>();
      // before checking ArrayList using isEmpty() method
      System.out.println("Is ArrayList empty: " + al.isEmpty());
      al.add(86);
      al.add(25);
      al.add(53);
      al.add(85);
      // after checking ArrayList using isEmpty() method
      System.out.println("Is ArrayList empty: " + al.isEmpty());
      for(Integer num : al)
      {
         System.out.println(num);
      }
   }
}
Posted by: Guest on October-29-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language