The problem is that java does not see the p
variable.
public class Main { static Collection<Persone> peoples = Arrays.asList(); public static void main(String[] args) { createModelInCollection(100); List<Persone> filtered = peoples .stream() .filter(p -->p.getName().startsWith("Ivan")) .collect(Collectors.toList()); } static void createModelInCollection(int i) { Persone persone = new Persone(); String[] name = { "Ivan", "Kola", "John", "Kate", "Nicole", "Tony", "Alex", "Brandi", "Megan", "Dima", "Frank", "Phil", "Kai", }; String[] lastName = { "Stark", "Aniston", "Kross", "Green", "Akira", "Jemenson", "Freeman", "Stiffler", "Phinch", "Obama", "Sokolov", }; for (int x = 0; x < i; x++) { persone.setAge(random(80)); persone.setName(name[random(name.length)]); persone.setLastName(lastName[random(lastName.length)]); if (x % 2 == 0) { persone.setGender("MAN"); } else { persone.setGender("WOMAN"); } peoples.add(persone); } } static int random(int i) { Random rand = new Random(); return rand.nextInt(i); } }
Error: Multiple markers at this line - p cannot be resolved - p cannot be resolved to a variable
Help to understand what the problem is.