tags:

views:

102

answers:

7

This is probably the simplest question ever asked, but if I have a running number like 23.928.4934.30, which variable should house that?

+5  A: 

A String. If you need special logic related to it, it might be a good idea to create your own class.

Hank Gay
+1  A: 

Unless you actually have a need to access different parts of it individually, just keep it in a String and use org.apache.commons.validator.routines.InetAddressValidator to check them.

Affe
+1  A: 

String is the object I would use. If I want to process/parse the address (like getting the 1st octet) I would use regex for it.

Tushar Tarkas
A: 

If you do need to access specific parts of it an int or a long may be useful too: things like 192.168.2/24 are probably easier to work with in that case.

+1  A: 

InetAddress

http://download.oracle.com/docs/cd/E17476_01/javase/1.4.2/docs/api/java/net/InetAddress.html

dminear
That's too restrictive. Numbers over 255 should likely be allowed in case of the OP.
BalusC
A: 

If you want to work with it directly in some sort of numerical way, you could consider a long[]

Steven Schlansker
+1  A: 

Because the question is "IP address-like" and not just for storing IP addresses, I'm going to recommend the following

Create your own class that has a List attribute. You can override toString to put dots between the numbers in the list. If for example you have numbers 123, 123, 123 and 123 in your list, your class can print them out like 123.123.123.123.

palto