I have 3 variables with long values timestamp1
timestamp2
timestamp3
and an arraylist timestampList
. I want to compare them in an if/else. It could be possible, that the three timestamps have different values, so I want to add the values with the min value to the list. I should also mention, that these timestamps are coming in every 2 minutes.
When the three variables are same, I could simply do
if(timestamp1 == timestamp2 && timestamp2 == timestamp3){
timestampList.add(timestamp 1); //since they are the same it doesn't matter which i add to the list
.
.
.
}
now in the else or else if I want to check the three timestamps and get the variable with the min value, not the value itself. Because I need the variable for other variables further in the code. Of course I also want to add the min value to the list too. I can imagine, that I could do more if/else branches in the else like
else{
if(timestamp1 < timestamp2){
if(timestamp1 < timestamp3){
...
}else{
...
}
}
}
but that would be too much and there is certainly a better way.
So I went with the idea of @Amadan and created an array with the timestamps. But after thinking a little bit, I came to the conclusion that it would be possible without getting the variable.
Then I calculate the minValue of the array.
Then I ask if the timestamps are equal to minValue
I mentioned in my question that I need the variable for later purposes. It was because I needed the name of the variable to decrement the count variable of the specific host. (the eafed... are hosts).
Thanks for all the answers!