Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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  =
   .collect(Collectors.groupingBy(e -> e.getName(),Collectors.counting()));
   return n;

This method is not working. What changes should i make and how to call this method.
Posts: 69847
  • 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.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic