我正在创建一个界面来管理不同周/不同影院的电影票预订。
我有电影课:
public class Film {
private String title;
private Double price;
private String ageRestriction;
private double rating;
private String genre;
private String location;
private String screenDay;
}一个FilmList类,用于在ArrayList中创建和存储所有电影:
public class FilmList {
private ArrayList <Film> filmArrayList;
public FilmList (){
this.filmArrayList = new ArrayList<>();
}
public void addFilm(Film films){
this.filmArrayList.add(films);
}这是图形单元界面。我想要做的是根据两个条件在ArrayList中捕获一个元素:从用户中选择的周和剧院,并添加一种方法来检查列表中是否有来自所选参数的一个元素。这一点很重要,因为每个电影实例都将在FXML文件的标签上被调用和“设置”(而且我正在考虑实现一个接口,用于在ArrayList中添加电影)。
谢谢大家。
发布于 2019-02-22 01:55:56
好的,在您的示例中,如下所示:
//try to find any movie that suits two predicates, 1st - that it's price is greater than 30( this is random number, you can put a value from your textfield here ) and 2nd - that it's title contains Spiderman ( again, put a value from your textfield title search here for your need )
Optional<Film> movie = listOfMovies.stream().filter(i -> i.getPrice() > 30 && i.getTitle.contains("Spiderman")).findAny();
// if any movie has been found to suits provided criterias
if(movie.isPresent())
{
//print it on screen, note method get()
//again this is just for example here, in your code,
// you can do with this result whatever you like
// for example show all data about that movie on screen
System.out.println("---->" +movie.get());
}
else
{
// if not found do nothing
System.out.println("Nothing found...");
}https://stackoverflow.com/questions/54818723
复制相似问题