Java examples for Network:Network Address
Returns a collection of all addresses which do not have a local scope (loopbacks etc).
//package com.java2s; import java.net.InetAddress; import java.util.ArrayList; import java.util.Collection; public class Main { /**//from w w w . j a v a 2 s . co m * Returns a collection of all addresses which do not have a local scope (loopbacks etc). * @param addresses all addresse * @return the addresses which are not loopbacks/linklocal */ public static Collection<InetAddress> getExternalAddresses( InetAddress[] addresses) { ArrayList<InetAddress> result = new ArrayList<InetAddress>(); for (InetAddress addr : addresses) { if (addr.isAnyLocalAddress() || addr.isLinkLocalAddress() || addr.isLoopbackAddress()) continue; result.add(addr); } return result; } }