I changed, or added some notes to,your code. see the comment.
public class WechatArray {
private static List<Map<String, String>> params; // isnot params a keyword??? // = new ArrayList<Map<String, String>>();
//>>>>>>>>>>>>>>>>>>
static WechatArray(){
params = new ArrayList<Map<String, String>>();
}
//<<<<<<<<<<<<<<<<<<
//添加
public static void adds(Map<String, String> map) {
// if (params == null) {
// params = new ArrayList<Map<String, String>>();
// }
params.add(map);
}
//检查
public static Map<String, String> findSn(String sn) {
Iterator<Map<String, String>> it = params.iterator();
while(it.hasNext()) {
Map<String, String> obj = it.next();
if (obj.get("sn").equals(sn)) {
return obj;
}
}
return null;
}
//删除
public static void delSn(String sn) {
Iterator<Map<String, String>> it = params.iterator();
while(it.hasNext()) {
Map<String, String> obj = it.next();
if (obj.get("sn").equals(sn)) {
it.remove(); ///smells!!!!!!!!!!!!!!!!
return;
}
}
}
}
在另一个类中这样操作:
String[] wechats = sqltxt.split(";");
String we = wechats[0];
String sn = wechats[1];
String sql1 = wechats[2].trim();
String sql2 = wechats[3].trim();
if (we.equals("WE")) {
Map<String, String> map = new HashMap<String, String>();
map.put("sn", sn);
map.put("sql1", sql1);
map.put("sql2", sql2);
System.out.println("in-----000------");
try {
WechatArray.adds(map);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("in-----2222------");
System.out.println("sn="+sn+"; sql1="+sql1+"; sql2="+sql2);
......
【 在 darlingpeng (坏同志式的好同志) 的大作中提到: 】
: 大家好,我需要一个公共的arraylist变量用于保存信息,所以我把它定义为一个类中的静态变量,定义及操作函数如下:
: [code=java]
: public class WechatArray {
: ...................
--
FROM 183.95.135.*