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

I have got a problem with forEach loop

Looks like I miss something. The error is "illegal character", "; expected".. but I cannot see where :/

    IntStream.range(0, 100).forEach(i -> {
          String template = templates[i % templates.length];
          String buzzword = buzzwords[i % buzzwords.length];
          String title = String.format(template, buzzword);
          Course c = new Course(title, "http://www.example.com");
          Review review  = new Review((i % 5) + 1, String.format("Moar %s please!!!", buzzword));
          review.setReviewer(students.get(i % students.size()));
          c.addReview(review);
          bunchOfCourses.add(c);
    });

A few things would help:

  • Can you link to the video or challenge where this came up?
  • Can you post the whole error text? Often it comes with the line number, character number, stack trace.
  • Can you post the whole code in this file?

SOLVED!

3 Answers

Use => instead of ->

I think this is Java not JavaScript

Yes, this is Java, not Javascript. Programming Java API in Spring. This is the course and video: https://teamtreehouse.com/library/populating-and-relationships

For some reason, this was IDE problem or something. I deleted part "forEach(i -> {" and wrote it again and everything works perfectly.