Here you can find the source of inetAddressCompare(final InetAddress address1, final InetAddress address2)
public static int inetAddressCompare(final InetAddress address1, final InetAddress address2)
//package com.java2s; /*/* w ww .ja v a2s. c o m*/ * Cacheonix Systems licenses this file to You under the LGPL 2.1 * (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.cacheonix.org/products/cacheonix/license-lgpl-2.1.htm * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.net.InetAddress; public class Main { public static int inetAddressCompare(final InetAddress address1, final InetAddress address2) { if (address1 == null || address2 == null) { return -1; } if (address1.equals(address2)) { return 0; } final byte[] ab1 = address1.getAddress(); final byte[] ab2 = address2.getAddress(); if (ab1.length > ab2.length) { return 1; } if (ab1.length < ab1.length) { return -1; } for (int i = 0; i < ab1.length; i++) { final byte b1 = ab1[i]; final byte b2 = ab2[i]; if (b1 > b2) { return 1; } if (b1 < b2) { return -1; } } return 0; } }