I have an array of String containing below elements
5.0,99,5.5,100,6.0,101
Now what I want to do I need to remove all the decimal value in string format like 5.0,5.5 and 6.0
so my final array should contain elements 99,100,101
so what I'd done so far is show in below code
public static String[] deleteElement(String[] str_array) {
//String[] str_array = {"item1","item2","item3"};
List<String> list = new ArrayList<String>(Arrays.asList(str_array));
list.remove("5.0");
list.remove("5.5");
list.remove("6.0");
return str_array = list.toArray(new String[0]);
}
I have hardcoded the values which is quite bad practice as the values in future may be more than the current values, so I want a way to remove by using index.
I have tried to remove using remove(index) also, using even index positioning like 0,2,4,but what actually happening is, after deletion of 5.0 , elements are shifted left side, so 100 comes into the 2nd position, and in next iteration 100 deleted.
So is there any way where I can construct a generic function so if there are more elements in decimal value so it can also be deleted.
NOTE: The string decimal values will always be residing on even index positioning.
