arraylist - Java: Checking if an IP address is in an Array List -
is there particular way check if ip address not exist in arraylist? right have arraylist made of strings of ip addresses (e.g. "192.168.0.4", etc.). after receiving packet i'd check if packet's ip address belongs in arraylist. at first thought suffice: for (int = 0; < mylist.size(); i++) { if (packet.getaddress().equals(inetaddress.getbyname(mylist.get(i)))) { system.out.println("this packet's ip address in list"); } else { system.out.println("this packet's ip address not in list!"); } i thought else statement solve situation wrong. suggestions appreciated. you have check entire list before know ip not there : boolean found = false; (int = 0; < mylist.size() && !found; i++) { if (packet.getaddress().equals(inetaddress.getbyname(mylist.get(i)))) { found = true; system.out.println("this packet's ip address in list"); } } if (!found) { system.out....