Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
master stewards:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
stewards:
  • salvin francis
  • Frits Walraven
  • Piet Souris

java streams

 
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to load file data in arraylist which I have done by creating a method. How can I count number of students using streams by creating a separate method for counting names. I have a student class with constructor, getters and setters.

I have a file having data as
Name: a
Subjects : eng, phy, chem
Name: b
Subjects : math, bio

//name is variable in student class // getName is the getter

List<Student> stu = new ArrayList<>():


public static Map<String,Long> names(List<Student> name, Predicate <Student> getName) {      
   Map<String, Long> n  = stu.stream()
   .filter(getName)    
   .collect(Collectors.groupingBy(e -> e.getName(),Collectors.counting()));
   System.out.println(Collectors.counting());
   return n;
}

This method is not working. What changes should i make and how to call this method.
 
Marshal
Posts: 67984
258
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to be confusing things, and your naming doesn't help. Who calls a Map n or a predicate getName? What's more, the getName title suggest you don't know what you want the predicate to do. We can't help if all you tell us is, “doesn't work”. What is the point of .filter(...) being followed by .groupingBy(...) using a name?

Let's move you to the correct forum, and let you give us more explanation.
 
Can't .... do .... plaid .... So I did this tiny ad instead:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!