I'm trying to build a hashMap from an ArrayList which contains all the variables I need plus their respective values.
The problem is, my arrayList contains variables with non numeric values (eg: var1 = "*$&/@"). How could I filter the data contained in the arrayList to get only the numeric strings.
I tried using regular expressions but the data get filtered too much and some of the variables I need get lost. I guess i'm not using the legit regex. So I tried matching the following regex and if not, assign "0" to my variable. Here's roughly what I've tried thus far:
private static final String REGEX = "-?\\d+(\\.\\d+)?";
//...
if (val_ens1_sol.matches(REGEX) && val_ens1_bord.matches(REGEX)) {
reslutatsMap.put(key_ens1_sol, val_ens1_sol);
reslutatsMap.put(key_ens1_bord, val_ens1_bord);
} else {
val_ens1_sol = "0";
val_ens1_sol = "0";
}