我需要拆分包含" 1,000.00,106,924.31"等数量的字符串。 。该怎么做??
我以前尝试过使用split by','但它给我的输出为1,000.00,106,924.31。 但我需要输出为1,000.00 106,924.31。
答案 0 :(得分:0)
你可以这样:
public static void main(String[] args) {
String amounts = "1,000.00,106,924.31";
List<String> results = new ArrayList<>();
do {
int indexOfFirstComma = amounts.indexOf(",");
String sub_amounts = amounts.substring(indexOfFirstComma+1);
String splitComma = sub_amounts.split(",")[0];
results.add(amounts.substring(0, indexOfFirstComma) + "," + splitComma);
if (sub_amounts.indexOf(",")>0) {
amounts = sub_amounts.substring(sub_amounts.indexOf(",")+1);
}else {
break;
}
}while (true);
results.forEach(System.out::println);
}