J
J
juffinhalli2014-06-14 15:53:44
Java
juffinhalli, 2014-06-14 15:53:44

JAVA. How to search through fields of objects in ArrayList?

There is a filled object:
ArrayList arpbase = new ArrayList();
the arphost class has fields:
public class arphost {
private String mac;
private String ip;
private String firm;
Task: in arpbase find the indexes of all arphost objects whose "ip" field contains "192.168"
In extreme cases, I'm ready to write a loop that will extract the local variable "ip" of each arpbase object, search for a substring and remember the indices of these objects.
However, I think there is a more elegant solution.
Thanks in advance for your advice

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Ololesha Ololoev, 2014-06-15
@alexeygrigorev

What you have written (loop and match for each element) is the only solution for this data structure.
A more elegant solution might be to use some kind of TreeSet, with data sorted by ip

L
lo-fi, 2014-06-20
@hrls

A more elegant solution is to use a library with map and filter functions like google guava or apache commons.
Or wait for the 8th java =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question