Concatenate string values with delimiter handling null and empty strings? [duplicate]
String joined = Stream.of(val1, val2, val3, val4) .filter(s -> s != null && !s.isEmpty()) .collect(Collectors.joining(“,”));
String joined = Stream.of(val1, val2, val3, val4) .filter(s -> s != null && !s.isEmpty()) .collect(Collectors.joining(“,”));
Use this code numberOnly will contain your desired output. String str=”sdfvsdf68fsdfsf8999fsdf09″; String numberOnly= str.replaceAll(“[^0-9]”, “”);