答复: 字符串替换求解
package cn.com.test;
import java.util.ArrayList;
import java.util.List;
public class TestString
{
public static void main( String[] args )
{
String a = "0,1,5,19";
String b = "1,2,4";
String c = "4,7,9";
String d = "0";
List<String> list = new ArrayList<String>();
list.add( a );
list.add( b );
list.add( c );
list.add( d );
/*
* 把 a b c d字符串中含有1或4的值分别该为8,10
*/
replaceString(list);
}
public static void replaceString(List<String> list){
String str = null;
List<String> listStr = new ArrayList<String>();
for(int i=0;i<list.size();i++){
str = list.get(i);
str = new String(","+str+",").replace(",1,", ",8,").replaceAll(",4,", ",10,");
str = str.substring(1, str.length()-1);
listStr.add(str);
}
for(int i=0;i<listStr.size();i++){
System.out.println(listStr.get(i));
}
}
}