I need to check Whether My ArrayList is null or Empty or Conatins any special character? ArrayList Debugging Image.
if(!lotNumArrList.contains(null)&&lotNumArrList!=null&&!lotNumArrList.isEmpty()){
{
}
}
try the below code:
Pattern p = Pattern.compile("[^a-z0-9 ]", Pattern.CASE_INSENSITIVE);
boolean hasSpecialChar = false;
if (lotNumArrList != null && lotNumArrList.size() > 0) {
for (int i = 0; i < lotNumArrList.size(); i++) {
String str = lotNumArrList.get(i).trim();
Matcher m = p.matcher(str);
boolean b = m.find();
if (b) {
hasSpecialChar = true;
break;
}
}
}
if (lotNumArrList.size()>0){
boolean isNull = false;
for (int i = 0;i>lotNumArrList.size();i++){
String itemValue = lotNumArrList.get(i).trim();
if (itemValue==null||itemValue.equalsIgnoreCase("")||itemValue.length()==0){
isNull = true;
break;
}else {
isNull = false;
}
}
if (!isNull) {
mDBHelper.getWritableDatabase();
mDBHelper.updateFIQTY(fiGoods, fiQty,fiUnWgt,totWgt); mDBHelper.closeDatabase();
}
}
Assuming your ArrayList is ArrayList, try the below code
boolean isArrValid = true;
String pattern = "^[a-zA-Z0-9]*$";
if (lotNumArrList != null && lotNumArrList.size() > 0) {
for (String str : lotNumArrList) {
if (str == null || !str.matches(pattern)) {
isArrValid = false;
break;
}
}
} else {
isArrValid = false;
}
if(isArrValid) {
//Your action
}
Hope it helps!
this is not tested yet. try if it works.
if (lotNumArrList == null || lotNumArrList.size == 0){
// your code here if null or empty
} else {
String pattern = "[^a-zA-Z0-9]"; // you can change this one on what you want to have in your string
for (String s : list)
if(s.matches(pattern)){
// your code here if found special characters
}
}
ArrayListis not empty or null. It has 3 elements.