Here is the stream "airportFilteredList" i am having trouble with, it should print the country name that matches the filter of the given "Turkey" string but it doesn't print anything to the console, using count() on the stream gives a value of 0
public void getFilteredAirportList(String filteredText){
System.out.println(filteredText); //returns Turkey
Predicate<Airport> filterCountry = u -> u.getCountry() == filteredText;
Stream<Airport> airportFilteredList = airportList.stream().filter(filterCountry);
airportFilteredList.forEach(u -> System.out.println(u.getCountry()));
}
I made a general stream without the filter as well from the same list but it works well and returns all country names of the airports.
public void getAirportList(){
Stream <Airport> airportStream = airportList.stream();
airportStream.forEach(u -> u.getCountry()); //returns Turkey
}
The ArrayList from which the Airport objects are retrived
ArrayList<Airport> airportList = new ArrayList<Airport>();
public void createAirport(String airport, String country, String continent,
String airfield_length) {
airportList.add(new Airport(airport, country, continent,
airfield_length));
}
The full source code is at https://github.com/Jointts/JavaExam/tree/master/JavaExam