String str="select * from table1 where a=?0 and b=?1";
List<String> arr=new ArrayList<String>();
arr.add("1");
arr.add("2");
Matcher m=Pattern.compile("\\?(\\d+)").matcher(str);
while(m.find()){
str=str.replace(m.group(),arr.get(Integer.parseInt(m.group(1))));
System.out.println(str);
}
m.find()就是下一个
m.group()就是?0,?1
m.group(1) 就是?后面的数字
str=str.replace(m.group(),arr.get(Integer.parseInt(m.group(1))));
意思就是用arr里面的值替换?0 ,?1