0

//使用Offer Id找出特定事件索引的最佳方法是什么?
使用核心 java 还是使用第三方库(如 Guava/Commons Collection)?

  public class Event{
        private String title;
        //other attributes
        private ArrayList<Offers> lOffers;
    }

    public class Offers{
        private Sring Id;
        private String offerName;
    }


    //Code
    List<PayPerViewTitles>  PayPerViewTitleList = someMethod();

/*

offerId -> Offers Object id property
**/
    private int findEventPositionByOfferId(List<Event> eventList, String offerId){
       // how to implement this method to find the Main Event using the 
       offer->id
    }

此对象用于映射服务器 JSON 响应,

4

1 回答 1

0

您可以使用地图将 id 保存为键,将对象保存为值,然后使用列表,如下所示:

List<Student> students = new ArrayList<>();
    Student student0 = Student.builder().id(1).name("wentjiang").age(23).build();
    Student student1 = Student.builder().id(2).name("wentjiang2").age(232).build();

    Map<Integer,Student> map = new HashMap<>();
    map.put(student0.getId(),student0);
    map.put(student1.getId(),student1);
    students.add(student0);
    students.add(student1);
    Integer findId = 2;
    Student student = map.get(findId);
    int index = students.indexOf(student);
    System.out.println(index);
于 2017-09-19T07:12:18.343 回答