0

in this program, i gather a nickname and an ip address for 50 different nicknames and IP addresses.

the ip address is separated into 4 integers (x.y.z.m) in it's class (which includes the nickname).

this method compares the x and y with the rest and records the nickname into a double string array. but i don't the same local network (same x and y) to be compared later in the loop so i want to delete each of the same x and y. how to do that?

7
  • 1
    Could you explain the use of the inner for-loop? Also, what is the type 'IPAddress'? Commented Oct 5, 2014 at 3:46
  • Edited and included class IPAddress. and the inner for-loop is acutally useless, thanks for bring it to my attention @Multithreader Commented Oct 5, 2014 at 4:04
  • Two suggestions: 1. Use descriptive variable names. 2. Use List. Commented Oct 5, 2014 at 4:08
  • Another suggestion: 3. Initialize your result array. (There is a lurking NullPointerException here.) Commented Oct 5, 2014 at 4:09
  • how would you initialize 'result'? @Code-Apprentice Commented Oct 5, 2014 at 4:30

2 Answers 2

1

In your case you can just null the positions in the array you want to ignore (and make sure your code skips null entries). However more generally speaking arrays are not the best data structure to use.

I am not entirely sure what you want to do, it sounds like you want a list of all nicknames which have an IP Address in the same /16 network? In that case, I would use a MultiMap and use the prefix as the key. Then you simple need to put all addresses and later on get the collection for each of them.

Guava or Apache Commons Lang have such a structure:

Sign up to request clarification or add additional context in comments.

Comments

0

Arrays are staticly sized, so you cannot easily remove an element from an array. I strongly suggest that you use a List type (such as ArrayList).

2 Comments

how can i make a List type out of addr which is already of type IPAddress?
@ShacoNotFound404 addr is of type IPAddress[] which can be replaced by List<IPAddress>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.