Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Why doesn't Java List have anything like the filter method like the filter method of Scala?

 
Ranch Hand
Posts: 1258
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Scala we have filter method for the lists. Why don't we have any such method for the lists in Java?

Thanks
 
Saloon Keeper
Posts: 10675
228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because in Java all these higher order functions are defined in Stream. You can easily get a stream from any collection using the Collection.stream() method.

The reason for this is that Java already existed for almost 20 years before they added higher order functions, so they couldn't easily add them to the collection interfaces without breaking a lot of existing code.
 
Monica Shiralkar
Ranch Hand
Posts: 1258
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I think in simple words we can say that Functions are not first class citizens in Java.
 
Stephan van Hulst
Saloon Keeper
Posts: 10675
228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how you concluded that from anything I said. What does it matter in what type the functions are declared?
 
Marshal
Posts: 65821
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:. . . Functions are not first class citizens in Java.

Have you ever tried anything to find out whether there are Function objects or not, and if so, whether they are first class citizens?
 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
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!