Answer the question
In order to leave comments, you need to log in
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
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question