Say I have an Integer list and I'm using Java 8 forEach method on the list to double its values. Say I have the following code:
List<Integer> l = Arrays.asList(2,3,6,1,9);
l.forEach(p->p*=2);
As forEach method take Consumer and calls it accept methos. I print the list after runnig the above code and the original list doesn't change.
As far as I understand Stream doesn't alter the source but here I just call accept method on each element...
Thank u in advace