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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 4 of 4

Thread: Help With Filters Java Programming

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help With Filters Java Programming

    I am new to java and do not understand how to use filters very well. I need to write a code that determines if an integer is not divisible by some value. A filter also contains an upstream filter so that this filter can be part of a chain of filters. please help me get started. thanks!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,152
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: Help With Filters Java Programming

    What do you mean when you use the word "filter"? Is it the standard English meaning?
    Or are there some specific java classes you are talking about?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    7
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Help With Filters Java Programming

    What do you mean by filter? I would use if-then statements from what you're making the program

  4. #4
    Member
    Join Date
    Apr 2012
    Posts
    161
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: Help With Filters Java Programming

    I assume he is referring to the new Java 8 filters.
    What a filter does is takes a stream of objects and checks for the condition you gave it. If the condition is true, it will be returned in the new stream.
    Here is a simple example
    List<Integer> list = new ArrayList<>();
    int[] nums = { 8, 9, 2, -1, 10, 3, 23, 13, 14, 28 };
    for (int n : nums)
        list.add(n);
     
    Stream<Integer> evens = list.stream().filter(n -> n % 2 == 0);

    The above code will find all even values in the list and add them to the new stream evens.
    Alternatively, you could have it return a list at the end of everything.
    List<Integer> evens = list.stream().filter(n -> n % 2 == 0).collect(Collectors.toList());

  5. The Following User Says Thank You to Parranoia For This Useful Post:

    Leklur (April 11th, 2014)

Similar Threads

  1. Linked Lists Java Programming HELPP P.S. I am a beginner in Java Programming
    By judemartin99 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 20th, 2013, 02:19 PM
  2. Applying filters to immages Horizontal Flip to an image using java
    By IBeeJava in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 5th, 2013, 07:04 PM
  3. Java Tip Aug 4, 2010 - How to use File Filters
    By helloworld922 in forum Java Programming Tutorials
    Replies: 0
    Last Post: August 4th, 2010, 05:08 PM
  4. Java Tip Aug 4, 2010 - How to use File Filters
    By helloworld922 in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: August 4th, 2010, 05:08 PM

Tags for this Thread