I have String "ORIGINAL_PAYMODE:90.23,VOUCHRE:30.10,ORIGINAL_PAYMODE:80.30,VOUCHRE:33.10" i need to Split and add all ORIGINAL_PAYMODE value occurring in String using stream api
In this case I need result of 90.23+80.30 = 170.53
code :
public static void main(String[] args) {
String reftype
="ORIGINAL_PAYMODE:90.23,VOUCHRE:30.10,ORIGINAL_PAYMODE:80.30,VOUCHRE:33.10";
Pattern COMMA = Pattern.compile(",");
Pattern p = Pattern.compile(":");
String result = COMMA.splitAsStream(reftype)
.filter(role -> role.contains("ORIGINAL_PAYMODE"))
.map(String::trim)
.collect(Collectors.joining(","));
System.out.println(result);