try { InetAddress address = InetAddress.getByName("224.0.0.1"); if (address.isMulticastAddress()) { System.out.println("Multicast address!"); } else { System.out.println("Not a multicast address!"); } } catch (UnknownHostException e) { e.printStackTrace(); }
try { InetAddress address = InetAddress.getLocalHost(); if (address.isMulticastAddress()) { System.out.println("Multicast address!"); } else { System.out.println("Not a multicast address!"); } } catch (UnknownHostException e) { e.printStackTrace(); }In this example, we create an InetAddress object for the local host's IP address. Since the local host IP address is not a multicast address, the isMulticastAddress() method will return false and we will print "Not a multicast address!". The package library for java.net.InetAddress is "java.net".