No more nonsense. See the following code:
/*** Determine whether the parameter is in the blacklist * @ Param name indicates the name to be determined * @ return true: in the blacklist */private Boolean inblackname (string name) {string [] blackname = {"black name 1", "blacklist 2", "No Name", "kaokao" ,}; for (INT I = 0; I <blackname. length; I ++) {If (blackname [I]. equals (name) {return true;} return false ;}
In fact, we should record the blacklist in a set to determine whether the set contains the name to be determined.
Private Static final set blacknames = new hashset (); static {blacknames. add ("black name 1"); blacknames. add ("blacklist 2"); blacknames. add ("No Name"); blacknames. add ("kaokao");}/*** determine whether the name is in the blacklist * @ Param name to be determined * @ return true: in the blacklist */private Boolean inblackname (string name) {return blacknames. contains (name );}
Set is used because the blacklist does not require sequential records, which saves storage space.
Set is faster and more convenient than loop judgment.
Of course, a better change to the code is to put the blacklist in the configuration file and transfer it to the memory when the system starts. This is not much to say.
The main purpose of this article is to tell new users not to use array loops to determine whether an object is in a set.