Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Spring Basics Using the MVC Architecture Add a CategoryController

Can GifRepository.findByCategoryId() be rewritten as functional using stream?

Here's how I did it.

import java.util.stream.Collectors;
    public List<Gif> findByCategoryId(int id) {
        return ALL_GIFS
                .stream()
                .filter(gif -> gif.getCategoryId() == id)
                .collect(Collectors.toList());
    }

1 Answer

You definitely can! I believe this course came out not long after Java 8 (which introduces streams, lambdas, etc. as far as I know). I think streams are much more common now as the functional programming paradigm is more popular in the Java world now than it used to be. One of the coolest aspects of programming in my opinion is how many different solutions there are to problems depending on how you think about something.

Cheers and happy coding!