Warning: Invalid argument supplied for foreach() in /home/customer/www/techndeck.com/public_html/wp-content/plugins/use-any-font/includes/functions/uaf_font_functions.php on line 469
Double the even/odd numbers ArrayList using Java 8 Streams - Techndeck

# Double the even/odd numbers ArrayList using Java 8 Streams

In this post, we will see how to double the even and odd numbers present in an ArrayList separately with the help of Java 8 Streams.

Let’s say: There is an ArrayList of 10 integer values as shown below. In the first example, using Streams, we are going to double each even integer of the ArrayList and In the second example, we are going to double odd integers.

Output 1:

## Example 2

Output 2:

That’s it. It’s that easy to double the even and odd numbers of ArrayList with the power of Java 8 Streams.

### If you like this post, please check out my other similar posts:

How to add/sum up the ArrayList integers using Java8 Streams

## 7 thoughts on “Double the even/odd numbers ArrayList using Java 8 Streams”

1. Bohdan Myslyvchuk says:

Hi, your filter function works only because of List input and ONLY because it has odd and even numbers. If you place there random even numbers, for example 22, 33, 44, 24, 56 – it won’t work it will do pow(x, 2) to all numbers, not only to even. Basically, our code incorrect in terms of what it should do

1. Hi Bohdan,

As what I understood, you said if you tried with list items [22, 33, 44, 24, 56], it’s not working as intended.

Well, I tried, it’s working completely fine.

Please correct me if I didn’t understand your question clearly. Kindly, let me know and i’ll try to help out asap.

Thanks

2. If you are interested in work in nursing, many online college classes for
nursing are available. This makes the students all-rounder and they
might be for sure that they can shall click virtually any tough
interview on the first attempt itself. Running genuine software
that you’ve legitimately purchased helps protect you
from these dangers and provides additional benefits,
including support to troubleshoot a problem when you’re printing out
you be sure that your computer and the facts about it are safe from system crashes or prying eyes.

3. Hello There. I found your blog using msn. This is an extremely well written article.
I’ll make sure to bookmark it and come back to read more of your useful info.
Thanks for the post. I’ll definitely comeback.

1. Deepak Verma says:

Thank you. I am glad that my content helped you.

Thanks

4. Jan says:

Hey,
lately I have finished preparing my ultimate tutorial:

+++ [Beginner’s Guide] How To Make A Website From Scratch +++

I would really apprecaite your feedback, so I can improve my craft.

If you know someone who may benefit from reading it, I would be really grateful for sharing a link.

Much love from Poland!
Cheers

1. Hello Jan,

Honestly, this is a wonderful website as you have accumulated almost everything that is required to build a website from scratch.

I am sure gonna use it for myself as well. It’s great stuff.

Let me share with one of friend too who are looking to start a website and your content could be helpful to him.

Cheers