August 2018
Intermediate to advanced
380 pages
10h 2m
English
Java is a classic example of a very imperative approach to programming. And hence, in its collections, you will encounter operations that are typical of imperative programming. For example, consider that you have an array of strings. They are the names of the employees of your company. You want to create a separate collection with only those employees whose names start with the letter 'A'. How do you do that in Java?
// Source collectionList<String> employees = new ArrayList<String>();employees.add("Ann");employees.add("John");employees.add("Amos");employees.add("Jack");// Those employees with their names starting with 'A'List<String> result = new ArrayList<String>();for (String e: employees) if (e.charAt(0) == 'A') result.add(e); ...