我需要检查我的ArrayList是null还是Empty或者Conatins是否有任何特殊字符? ArrayList调试映像。
if(!lotNumArrList.contains(null)&&lotNumArrList!=null&&!lotNumArrList.isEmpty()){
{
}
}
答案 0 :(得分:1)
试试这个:
boolean hasSpecialChar = false;
if (lotNumArrList != null && lotNumArrList.size() > 0) {
for (int i = 0; i < lotNumArrList.size(); i++) {
String value = lotNumArrList.get(i).trim();
if (value.length() > 0 && value.contains(",")) {
hasSpecialChar = true;
break;
}
}
}
答案 1 :(得分:0)
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();
}
}
答案 2 :(得分:0)
Pattern p = Pattern.compile("[^a-zA-Z]");
if(lotNumArrList!=null && !lotNumArrList.isEmpty() && !p.matcher(string).find()){
}
答案 3 :(得分:0)
尚未测试。试试它是否有效。
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
}
}
答案 4 :(得分:0)
假设您的ArrayList是ArrayList,请尝试以下代码
FilePath
希望它有所帮助!
答案 5 :(得分:0)
尝试以下代码:
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;
}
}
}