//使用要约ID的特定事件索引的最佳方法是什么?
使用Core 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响应,
您可以使用映射将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);