June 2018
Intermediate to advanced
280 pages
7h 46m
English
Everyone working with Java is aware of collections. We use collections in an imperative way: we tell the program how to do what it's supposed to do. Let's take the following example in which we instantiate a collection of 10 integers, from 1 to 10:
List<Integer> list = new ArrayList<Integer>();for (int i = 0; i < 10; i++){ list.add(i);}
Now, we will create another collection in which we will filter in only the odd numbers:
List<Integer> odds = new ArrayList<Integer>();for (int val : list){ if (val % 2 == 0) odds.add(val);}
At the end, we want to print the results:
for (int val : odds){ System.out.print(val);}
As you can see, we wrote quite a bit of code to perform three basic operations: ...
Read now
Unlock full access