Java – given a list of IP addresses, how do you find min, max?
•
Java
In Java, I have an ArrayList of IP addresses How do I find the minimum and maximum values?
I have used collection Min () but it doesn't work. The following conditions are given:
192.168.0.1 <--min 192.168.0.250 192.168.0.9 <--max
How can I return
192.168.0.1 <--min 192.168.0.250 <--max
Replace?
ArrayList is retrieved from the database I need to do this every tick (every tick interval is 5 seconds) The maximum number of IP addresses may reach 300
Solution
Converts IP addresses to long integers and sorts them You can use binary arithmetic / operators to convert 192.168 0.1 to integer:
( 192 << 24 ) + ( 168 << 16 ) + ( 0 << 8 ) + ( 1 << 0 )
wait. Please read the following notes about using the correct data type
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码