Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Iterating over collections in Java 8

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Thanked 0 Times in 0 Posts

    Default Iterating over collections in Java 8

    Hi all,

    Today I installed jdk1.8.0_20 on my computer and typed a simple example code in MyEclipse 6.0 IDE, the code listed below:

    import java.util.List;

    public class Test5
    public static void main(String[] args)
    List<String> features = Arrays.asList("Lambdas", "Default Method", "Stream API", "Date and Time API");
    features.forEach(n -> System.out.println(n));

    the MyEclipse Editor shows some errors like "Arrays can not be resolved" and "n can not be resolved".
    I did use jdk 8 in the build path, but it seems like the jdk 8 did not function properly.

    I don't know what's the problem. Any idea? pls help.


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Thanked 120 Times in 104 Posts

    Default Re: Iterating over collections in Java 8

    The class Arrays needs to be imported before you can use it. That has been the same in all versions of java.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 688 Times in 675 Posts

    Default Re: Iterating over collections in Java 8

    Please post your code correctly using code or highlight tags which are explained near the top of this link.

Similar Threads

  1. Help making and iterating through ArrayList (Java Beginner)
    By Sammis in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 20th, 2013, 07:58 AM
  2. Java Collections and Log4j
    By francisolie in forum Java Theory & Questions
    Replies: 0
    Last Post: June 14th, 2013, 03:17 AM
  3. Replies: 4
    Last Post: May 29th, 2013, 12:24 AM
  4. [SOLVED] Iterating through an ArrayList
    By Actinistia in forum Collections and Generics
    Replies: 2
    Last Post: October 31st, 2011, 03:19 PM
  5. Iterating a String
    By av8 in forum What's Wrong With My Code?
    Replies: 18
    Last Post: July 7th, 2011, 01:37 PM