Self-summary, what is not in place, please correct the supplement, thank you!
Objective: To make the procedure more rigorous
Object validation is NOT NULL: if (null! = obj)
List validation is not empty: if (null! = List && list.size () > 0)
Map validation is not empty: if (null! = Map && map.size () > 0)
Well, nonsense not much to say, on the code
Entity class student (random one)
Packagecom.core.test; Public classStudent {Private intID; PrivateString name; Public intgetId () {returnID; } Public voidSetId (intID) { This. ID =ID; } PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; }}
Test class Collectiontest
Packagecom.core.test;Importjava.util.ArrayList;ImportJava.util.HashMap;Importjava.util.List;ImportJava.util.Map; Public classCollectiontest { Public Static voidMain (string[] args) {Student stu=NewStudent (); System.out.println ("Student Object--" +Stu); List<Student> stulist =NewArraylist<student>(); if(NULL! = stulist && stulist.size () > 0) {System.out.println ("Student list is not empty"); } Else{System.out.println ("Student list is empty"); } System.out.println ("Student list-->" +stulist); //map<string,object> Map = null;map<string, object> map =NewHashmap<string, object>(); //map.put ("Stu", Stu); if(NULL! = Map && map.size () > 0) {System.out.println ("Map is not empty"); } Else{System.out.println ("Map is empty"); } System.out.println ("Map Collection--" +map); }}
Results:
Student objects--[email protected]student list is empty student list--[]map is empty map collection -->{}
Summary: The set determines non-null except to verify if NULL, and also to verify that size is greater than 0
Non-null Judgment of Java objects and collections