Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Hold address as it should be -- as 32-bit integer, and increment it in this form. Convert it from or to <code>String</code> only if required. Example is below. My <code>IPAddress</code> class is complete and functional.</p> <pre><code>class IPAddress { private final int value; public IPAddress(int value) { this.value = value; } public IPAddress(String stringValue) { String[] parts = stringValue.split("\\."); if( parts.length != 4 ) { throw new IllegalArgumentException(); } value = (Integer.parseInt(parts[0], 10) &lt;&lt; (8*3)) &amp; 0xFF000000 | (Integer.parseInt(parts[1], 10) &lt;&lt; (8*2)) &amp; 0x00FF0000 | (Integer.parseInt(parts[2], 10) &lt;&lt; (8*1)) &amp; 0x0000FF00 | (Integer.parseInt(parts[3], 10) &lt;&lt; (8*0)) &amp; 0x000000FF; } public int getOctet(int i) { if( i&lt;0 || i&gt;=4 ) throw new IndexOutOfBoundsException(); return (value &gt;&gt; (i*8)) &amp; 0x000000FF; } public String toString() { StringBuilder sb = new StringBuilder(); for(int i=3; i&gt;=0; --i) { sb.append(getOctet(i)); if( i!= 0) sb.append("."); } return sb.toString(); } @Override public boolean equals(Object obj) { if( obj instanceof IPAddress ) { return value==((IPAddress)obj).value; } return false; } @Override public int hashCode() { return value; } public int getValue() { return value; } public IPAddress next() { return new IPAddress(value+1); } } public class App13792784 { /** * @param args */ public static void main(String[] args) { IPAddress ip1 = new IPAddress("192.168.0.1"); System.out.println("ip1 = " + ip1); IPAddress ip2 = new IPAddress("192.168.0.255"); System.out.println("ip2 = " + ip2); System.out.println("Looping:"); do { ip1 = ip1.next(); System.out.println(ip1); } while(!ip1.equals(ip2)); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload