Searching in a ArrayList with custom objects for certain strings

前端 未结 9 577
感情败类
感情败类 2020-12-01 02:09

I have a ArrayList with custom objects. I want to search inside this ArrayList for Strings.

The class for the objects look like this:

public class Da         


        
相关标签:
9条回答
  • 2020-12-01 02:32

    For a custom class to work properly in collections you'll have to implement/override the equals() methods of the class. For sorting also override compareTo().

    See this article or google about how to implement those methods properly.

    0 讨论(0)
  • 2020-12-01 02:34
    boolean found;
    
    for(CustomObject obj : ArrayOfCustObj) {
    
       if(obj.getName.equals("Android")) {
    
          found = true;
       }
    }
    
    0 讨论(0)
  • 2020-12-01 02:36

    The easy way is to make a for where you verify if the atrrtibute name of the custom object have the desired string

        for(Datapoint d : dataPointList){
            if(d.getName() != null && d.getName().contains(search))
               //something here
        }
    

    I think this helps you.

    0 讨论(0)
提交回复
热议问题