SlideShare a Scribd company logo
1 of 41
Java Foundations
Maps, Lambda
and Stream API
Your Course
Instructors
Svetlin Nakov
George Georgiev
The Judge System
Sending your Solutions
for Automated Evaluation
Testing Your Code in the Judge System
 Test your code online in the SoftUni Judge system:
https://judge.softuni.org/Contests/3294
Associative Arrays,
Lambda and Stream API
Collections and Queries
Table of Contents
1. Associative Arrays (Maps)
 HashMap <key, value>
 LinkedHashMap <key, value>
 TreeMap <key, value>
2. Lambda Expressions
3. Java Stream API
 Filtering
 Mapping
 Ordering
Associative Arrays
Collection of Key and Value Pairs
 Associative arrays are arrays indexed by keys
 Not by the numbers 0, 1, 2, … (like arrays)
 Hold a set of pairs {key  value}
Associative Arrays (Maps)
9
John Smith +1-555-8976
Lisa Smith +1-555-1234
Sam Doe +1-555-5030
Key Value
Collections of Key and Value Pairs
 HashMap<K, V>
 Keys are unique
 Uses a hash-table + list
 LinkedHashMap<K, V>
 Keys are unique
 Keeps the keys in order of addition
 TreeMap<K, V>
 Keys are unique
 Keeps its keys always sorted
 Uses a balanced search tree
10
 put(key, value) method
 remove(key) method
Built-In Methods
11
HashMap<String, Integer> airplanes = new HashMap<>();
airplanes.put("Boeing 737", 130);
airplanes.remove("Boeing 737");
HashMap<String, Integer> airplanes = new HashMap<>();
airplanes.put("Boeing 737", 130);
airplanes.put("Airbus A320", 150);
 containsKey(key)
 containsValue(value) – slow operation!
Built-In methods (2)
12
HashMap<String, Integer> map = new HashMap<>();
map.put("Airbus A320", 150);
System.out.println(map.containsValue(150)); //true
System.out.println(map.containsValue(100)); //false
HashMap<String, Integer> map = new HashMap<>();
map.put("Airbus A320", 150);
if (map.containsKey("Airbus A320"))
System.out.println("Airbus A320 key exists");
HashMap: put()
13
HashMap<String, String>
Key Value
Hash Function
Pesho 0881-123-987
Gosho 0881-123-789
Alice 0881-123-978
HashMap: remove()
14
HashMap<String, String>
Key Value
Pesho Pesho
Gosho
0881-123-987
0881-123-789
Alice 0881-123-978
Hash Function
Pesho 0881-123-987
TreeMap<K, V> – Example
15
TreeMap
<String, String>
Key Value
Alice +359-899-55-592
Comparator
Function
Map<String, Double> fruits = new LinkedHashMap<>();
fruits.put("banana", 2.20);
fruits.put("kiwi", 4.50);
for (Map.Entry<K, V> entry : fruits.entrySet()) {
System.out.printf("%s -> %.2f%n",
entry.getKey(), entry.getValue());
}
 Iterate through objects of type Map.Entry<K, V>
 Cannot modify the collection (read-only)
Iterating Through Map
16
entry.getKey() -> fruit name
entry.getValue() -> fruit price
 Read a list of real numbers and print them in ascending order
along with their number of occurrences
Problem: Count Real Numbers
17
8 2 2 8 2
2 -> 3
8 -> 2
1 5 1 3
1 -> 2
3 -> 1
5 -> 1
Solution: Count Real Numbers
18
double[] nums = Arrays.stream(sc.nextLine().split(" "))
.mapToDouble(Double::parseDouble).toArray();
Map<Double, Integer> counts = new TreeMap<>();
for (double num : nums) {
if (!counts.containsKey(num))
counts.put(num, 0);
counts.put(num, counts.get(num) + 1);
}
for (Map.Entry<Double, Integer> entry : counts.entrySet()) {
DecimalFormat df = new DecimalFormat("#.#######");
System.out.printf("%s -> %d%n", df.format(entry.getKey()), entry.getValue());
}
Overwrite
the value
 Read 2 * N lines of pairs word and synonym
 Each word may have many synonyms
Problem: Words Synonyms
19
3
cute
adorable
cute
charming
smart
clever
cute - adorable, charming
smart - clever
Solution: Word Synonyms
20
int n = Integer.parseInt(sc.nextLine());
Map<String, ArrayList<String>> words = new LinkedHashMap<>();
for (int i = 0; i < n; i++) {
String word = sc.nextLine();
String synonym = sc.nextLine();
words.putIfAbsent(word, new ArrayList<>());
words.get(word).add(synonym);
}
// TODO: Print each word and synonyms
Adding the key if
it does not exist
Lambda Expressions
Anonymous Functions
Lambda Functions
 A lambda expression is an anonymous function
containing expressions and statements
 Lambda expressions
 Use the lambda operator ->
 Read as "goes to"
 The left side specifies the input parameters
 The right side holds the expression or statement
22
(a -> a > 5)
 Lambda functions are inline methods (functions)
that take input parameters and return values:
Lambda Functions
23
x -> x / 2 static int func(int x) { return x / 2; }
static boolean func(int x) { return x != 0; }
x -> x != 0
() -> 42 static int func() { return 42; }
Stream API
Traversing and Querying Collections
 min() - finds the smallest element in a collection:
 max() - finds the largest element in a collection:
Processing Arrays with Stream API (1)
25
int min = Arrays.stream(new int[]{15, 25, 35}).min().getAsInt();
int max = Arrays.stream(new int[]{15, 25, 35}).max().getAsInt();
35
int min = Arrays.stream(new int[]{15, 25, 35}).min().orElse(2);
int min = Arrays.stream(new int[]{}).min().orElse(2); // 2
15
 sum() - finds the sum of all elements in a collection:
 average() - finds the average of all elements:
Processing Arrays with Stream API (2)
26
int sum = Arrays.stream(new int[]{15, 25, 35}).sum();
double avg = Arrays.stream(new int[]{15, 25, 35})
.average().getAsDouble();
75
25.0
 min()
Processing Collections with Stream API (1)
27
ArrayList<Integer> nums = new ArrayList<>() {{
add(15); add(25); add(35);
}};
int min = nums.stream().mapToInt(Integer::intValue)
.min().getAsInt();
int min = nums.stream()
.min(Integer::compareTo).get();
15
 max()
 sum()
Processing Collections with Stream API (2)
28
int max = nums.stream().mapToInt(Integer::intValue)
.max().getAsInt();
int max = nums.stream()
.max(Integer::compareTo).get();
int sum = nums.stream()
.mapToInt(Integer::intValue).sum();
35
75
 average()
Processing Collections with Stream API (3)
29
double avg = nums.stream()
.mapToInt(Integer::intValue)
.average()
.getAsDouble(); 25.0
 map() - manipulates elements in a collection:
Manipulating Collections
30
String[] words = {"abc", "def", "geh", "yyy"};
words = Arrays.stream(words)
.map(w -> w + "yyy")
.toArray(String[]::new);
//abcyyy, defyyy, gehyyy, yyyyyy
int[] nums = Arrays.stream(sc.nextLine().split(" "))
.mapToInt(e -> Integer.parseInt(e))
.toArray();
Parse each
element to
Integer
 Using toArray(), toList() to convert collections:
Converting Collections
31
int[] nums = Arrays.stream(sc.nextLine().split(" "))
.mapToInt(e -> Integer.parseInt(e))
.toArray();
List<Integer> nums = Arrays.stream(sc.nextLine()
.split(" "))
.map(e -> Integer.parseInt(e))
.collect(Collectors.toList());
 Using filter()
Filtering Collections
32
int[] nums = Arrays.stream(sc.nextLine().split(" "))
.mapToInt(e -> Integer.parseInt(e))
.filter(n -> n > 0)
.toArray();
 Read a string array
 Print only words which length is even
Problem: Word Filter
33
kiwi orange banana apple
kiwi
orange
banana
pizza cake pasta chips cake
Solution: Word Filter
34
String[] words =
Arrays.stream(sc.nextLine().split(" "))
.filter(w -> w.length() % 2 == 0)
.toArray(String[]::new);
for (String word : words) {
System.out.println(word);
}
 Using sorted() to sort collections:
Sorting Collections
35
nums = nums.stream()
.sorted((n1, n2) -> n1.compareTo(n2))
.collect(Collectors.toList());
nums = nums.stream()
.sorted((n1, n2) -> n2.compareTo(n1))
.collect(Collectors.toList());
Ascending
(Natural) Order
Descending
Order
 Using sorted() to sort collections by multiple criteria:
Sorting Collections by Multiple Criteria
36
Map<Integer, String> products = new HashMap<>();
products.entrySet()
.stream()
.sorted((e1, e2) -> {
int res = e2.getValue().compareTo(e1.getValue());
if (res == 0)
res = e1.getKey().compareTo(e2.getKey());
return res; })
.forEach(e -> System.out.println(e.getKey() + " " + e.getValue()));
Second criteria
Terminates the stream
Using Functional forEach (1)
37
Map<String, ArrayList<Integer>> arr = new HashMap<>();
arr.entrySet().stream()
.sorted((a, b) -> {
if (a.getKey().compareTo(b.getKey()) == 0) {
int sumFirst = a.getValue().stream().mapToInt(x -> x).sum();
int sumSecond = b.getValue().stream().mapToInt(x -> x).sum();
return sumFirst - sumSecond;
}
return b.getKey().compareTo(a.getKey());
})
Second criteria
Descending sorting
Using Functional forEach (2)
38
.forEach(pair -> {
System.out.println("Key: " + pair.getKey());
System.out.print("Value: ");
pair.getValue().sort((a, b) -> a.compareTo(b));
for (int num : pair.getValue()) {
System.out.printf("%d ", num);
}
System.out.println();
});
 Read a list of numbers
 Print largest 3, if there are less than 3, print all of them
Problem: Largest 3 Numbers
39
10 30 15 20 50 5
50 30 20
1 2 3
3 2 1
20 30
30 20
Solution: Largest 3 Numbers
40
List<Integer> nums = Arrays
.stream(sc.nextLine().split(" "))
.map(e -> Integer.parseInt(e))
.sorted((n1, n2) -> n2.compareTo(n1))
.limit(3)
.collect(Collectors.toList());
for (int num : nums) {
System.out.print(num + " ");
}
 …
 …
 …
Summary
 Maps hold {key  value} pairs
 Keyset holds a set of unique keys
 Values hold a collection of values
 Iterating over a map
takes the entries as Map.Entry<K, V>
 Lambda and Stream API help
collection processing
 …
 …
 …
Next Steps
 Join the SoftUni "Learn To Code" Community
 Access the Free Coding Lessons
 Get Help from the Mentors
 Meet the Other Learners
https://softuni.org

More Related Content

What's hot

Java Methods
Java MethodsJava Methods
Java MethodsOXUS 20
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and OperatorsSunil OS
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3Sunil OS
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstractionIntro C# Book
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritanceIntro C# Book
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4Sunil OS
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in JavaVadym Lotar
 
04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructorHaresh Jaiswal
 
CSS Unit II - Array, Function and String
CSS Unit II - Array, Function and StringCSS Unit II - Array, Function and String
CSS Unit II - Array, Function and StringRahulTamkhane
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and ConcurrencySunil OS
 
Exception Handling
Exception HandlingException Handling
Exception HandlingSunil OS
 
Java 8 Default Methods
Java 8 Default MethodsJava 8 Default Methods
Java 8 Default MethodsHaim Michael
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)Olve Maudal
 
Threads V4
Threads  V4Threads  V4
Threads V4Sunil OS
 
Collection v3
Collection v3Collection v3
Collection v3Sunil OS
 

What's hot (20)

07. Arrays
07. Arrays07. Arrays
07. Arrays
 
Java Methods
Java MethodsJava Methods
Java Methods
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and Operators
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3
 
OOP V3.1
OOP V3.1OOP V3.1
OOP V3.1
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritance
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
 
04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructor
 
CSS Unit II - Array, Function and String
CSS Unit II - Array, Function and StringCSS Unit II - Array, Function and String
CSS Unit II - Array, Function and String
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and Concurrency
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
 
Java 8 Default Methods
Java 8 Default MethodsJava 8 Default Methods
Java 8 Default Methods
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)
 
Threads V4
Threads  V4Threads  V4
Threads V4
 
Collection v3
Collection v3Collection v3
Collection v3
 

Similar to Java Foundations: Maps, Lambda and Stream API

Chapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQChapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQIntro C# Book
 
Legacy lambda code
Legacy lambda codeLegacy lambda code
Legacy lambda codePeter Lawrey
 
Collections In Scala
Collections In ScalaCollections In Scala
Collections In ScalaKnoldus Inc.
 
Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)Robert Metzger
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
 
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...CloudxLab
 
Computation of Semi-Magic Squares Generated by Serpentine Matrices
Computation of Semi-Magic Squares Generated by Serpentine MatricesComputation of Semi-Magic Squares Generated by Serpentine Matrices
Computation of Semi-Magic Squares Generated by Serpentine MatricesLossian Barbosa Bacelar Miranda
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About RubyIan Bishop
 
Address calculation-sort
Address calculation-sortAddress calculation-sort
Address calculation-sortVasim Pathan
 
Programs in array using SWIFT
Programs in array using SWIFTPrograms in array using SWIFT
Programs in array using SWIFTvikram mahendra
 
Python_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdfPython_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdfAnonymousUser67
 

Similar to Java Foundations: Maps, Lambda and Stream API (20)

Spark workshop
Spark workshopSpark workshop
Spark workshop
 
Chapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQChapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQ
 
Legacy lambda code
Legacy lambda codeLegacy lambda code
Legacy lambda code
 
Scala Collections
Scala CollectionsScala Collections
Scala Collections
 
Scala collections
Scala collectionsScala collections
Scala collections
 
Collections In Scala
Collections In ScalaCollections In Scala
Collections In Scala
 
07 java collection
07 java collection07 java collection
07 java collection
 
Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)Stratosphere Intro (Java and Scala Interface)
Stratosphere Intro (Java and Scala Interface)
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Operations on rdd
Operations on rddOperations on rdd
Operations on rdd
 
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
 
Computation of Semi-Magic Squares Generated by Serpentine Matrices
Computation of Semi-Magic Squares Generated by Serpentine MatricesComputation of Semi-Magic Squares Generated by Serpentine Matrices
Computation of Semi-Magic Squares Generated by Serpentine Matrices
 
Scala by Luc Duponcheel
Scala by Luc DuponcheelScala by Luc Duponcheel
Scala by Luc Duponcheel
 
Programming in R
Programming in RProgramming in R
Programming in R
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About Ruby
 
Address calculation-sort
Address calculation-sortAddress calculation-sort
Address calculation-sort
 
CLUSTERGRAM
CLUSTERGRAMCLUSTERGRAM
CLUSTERGRAM
 
Programs in array using SWIFT
Programs in array using SWIFTPrograms in array using SWIFT
Programs in array using SWIFT
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
 
Python_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdfPython_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdf
 

More from Svetlin Nakov

BG-IT-Edu: отворено учебно съдържание за ИТ учители
BG-IT-Edu: отворено учебно съдържание за ИТ учителиBG-IT-Edu: отворено учебно съдържание за ИТ учители
BG-IT-Edu: отворено учебно съдържание за ИТ учителиSvetlin Nakov
 
Programming World in 2024
Programming World in 2024Programming World in 2024
Programming World in 2024Svetlin Nakov
 
AI Tools for Business and Startups
AI Tools for Business and StartupsAI Tools for Business and Startups
AI Tools for Business and StartupsSvetlin Nakov
 
AI Tools for Scientists - Nakov (Oct 2023)
AI Tools for Scientists - Nakov (Oct 2023)AI Tools for Scientists - Nakov (Oct 2023)
AI Tools for Scientists - Nakov (Oct 2023)Svetlin Nakov
 
AI Tools for Entrepreneurs
AI Tools for EntrepreneursAI Tools for Entrepreneurs
AI Tools for EntrepreneursSvetlin Nakov
 
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023Svetlin Nakov
 
AI Tools for Business and Personal Life
AI Tools for Business and Personal LifeAI Tools for Business and Personal Life
AI Tools for Business and Personal LifeSvetlin Nakov
 
Дипломна работа: учебно съдържание по ООП - Светлин Наков
Дипломна работа: учебно съдържание по ООП - Светлин НаковДипломна работа: учебно съдържание по ООП - Светлин Наков
Дипломна работа: учебно съдържание по ООП - Светлин НаковSvetlin Nakov
 
Дипломна работа: учебно съдържание по ООП
Дипломна работа: учебно съдържание по ООПДипломна работа: учебно съдържание по ООП
Дипломна работа: учебно съдържание по ООПSvetlin Nakov
 
Свободно ИТ учебно съдържание за учители по програмиране и ИТ
Свободно ИТ учебно съдържание за учители по програмиране и ИТСвободно ИТ учебно съдържание за учители по програмиране и ИТ
Свободно ИТ учебно съдържание за учители по програмиране и ИТSvetlin Nakov
 
AI and the Professions of the Future
AI and the Professions of the FutureAI and the Professions of the Future
AI and the Professions of the FutureSvetlin Nakov
 
Programming Languages Trends for 2023
Programming Languages Trends for 2023Programming Languages Trends for 2023
Programming Languages Trends for 2023Svetlin Nakov
 
IT Professions and How to Become a Developer
IT Professions and How to Become a DeveloperIT Professions and How to Become a Developer
IT Professions and How to Become a DeveloperSvetlin Nakov
 
GitHub Actions (Nakov at RuseConf, Sept 2022)
GitHub Actions (Nakov at RuseConf, Sept 2022)GitHub Actions (Nakov at RuseConf, Sept 2022)
GitHub Actions (Nakov at RuseConf, Sept 2022)Svetlin Nakov
 
IT Professions and Their Future
IT Professions and Their FutureIT Professions and Their Future
IT Professions and Their FutureSvetlin Nakov
 
How to Become a QA Engineer and Start a Job
How to Become a QA Engineer and Start a JobHow to Become a QA Engineer and Start a Job
How to Become a QA Engineer and Start a JobSvetlin Nakov
 
Призвание и цели: моята рецепта
Призвание и цели: моята рецептаПризвание и цели: моята рецепта
Призвание и цели: моята рецептаSvetlin Nakov
 
What Mongolian IT Industry Can Learn from Bulgaria?
What Mongolian IT Industry Can Learn from Bulgaria?What Mongolian IT Industry Can Learn from Bulgaria?
What Mongolian IT Industry Can Learn from Bulgaria?Svetlin Nakov
 
How to Become a Software Developer - Nakov in Mongolia (Oct 2022)
How to Become a Software Developer - Nakov in Mongolia (Oct 2022)How to Become a Software Developer - Nakov in Mongolia (Oct 2022)
How to Become a Software Developer - Nakov in Mongolia (Oct 2022)Svetlin Nakov
 
Blockchain and DeFi Overview (Nakov, Sept 2021)
Blockchain and DeFi Overview (Nakov, Sept 2021)Blockchain and DeFi Overview (Nakov, Sept 2021)
Blockchain and DeFi Overview (Nakov, Sept 2021)Svetlin Nakov
 

More from Svetlin Nakov (20)

BG-IT-Edu: отворено учебно съдържание за ИТ учители
BG-IT-Edu: отворено учебно съдържание за ИТ учителиBG-IT-Edu: отворено учебно съдържание за ИТ учители
BG-IT-Edu: отворено учебно съдържание за ИТ учители
 
Programming World in 2024
Programming World in 2024Programming World in 2024
Programming World in 2024
 
AI Tools for Business and Startups
AI Tools for Business and StartupsAI Tools for Business and Startups
AI Tools for Business and Startups
 
AI Tools for Scientists - Nakov (Oct 2023)
AI Tools for Scientists - Nakov (Oct 2023)AI Tools for Scientists - Nakov (Oct 2023)
AI Tools for Scientists - Nakov (Oct 2023)
 
AI Tools for Entrepreneurs
AI Tools for EntrepreneursAI Tools for Entrepreneurs
AI Tools for Entrepreneurs
 
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023
 
AI Tools for Business and Personal Life
AI Tools for Business and Personal LifeAI Tools for Business and Personal Life
AI Tools for Business and Personal Life
 
Дипломна работа: учебно съдържание по ООП - Светлин Наков
Дипломна работа: учебно съдържание по ООП - Светлин НаковДипломна работа: учебно съдържание по ООП - Светлин Наков
Дипломна работа: учебно съдържание по ООП - Светлин Наков
 
Дипломна работа: учебно съдържание по ООП
Дипломна работа: учебно съдържание по ООПДипломна работа: учебно съдържание по ООП
Дипломна работа: учебно съдържание по ООП
 
Свободно ИТ учебно съдържание за учители по програмиране и ИТ
Свободно ИТ учебно съдържание за учители по програмиране и ИТСвободно ИТ учебно съдържание за учители по програмиране и ИТ
Свободно ИТ учебно съдържание за учители по програмиране и ИТ
 
AI and the Professions of the Future
AI and the Professions of the FutureAI and the Professions of the Future
AI and the Professions of the Future
 
Programming Languages Trends for 2023
Programming Languages Trends for 2023Programming Languages Trends for 2023
Programming Languages Trends for 2023
 
IT Professions and How to Become a Developer
IT Professions and How to Become a DeveloperIT Professions and How to Become a Developer
IT Professions and How to Become a Developer
 
GitHub Actions (Nakov at RuseConf, Sept 2022)
GitHub Actions (Nakov at RuseConf, Sept 2022)GitHub Actions (Nakov at RuseConf, Sept 2022)
GitHub Actions (Nakov at RuseConf, Sept 2022)
 
IT Professions and Their Future
IT Professions and Their FutureIT Professions and Their Future
IT Professions and Their Future
 
How to Become a QA Engineer and Start a Job
How to Become a QA Engineer and Start a JobHow to Become a QA Engineer and Start a Job
How to Become a QA Engineer and Start a Job
 
Призвание и цели: моята рецепта
Призвание и цели: моята рецептаПризвание и цели: моята рецепта
Призвание и цели: моята рецепта
 
What Mongolian IT Industry Can Learn from Bulgaria?
What Mongolian IT Industry Can Learn from Bulgaria?What Mongolian IT Industry Can Learn from Bulgaria?
What Mongolian IT Industry Can Learn from Bulgaria?
 
How to Become a Software Developer - Nakov in Mongolia (Oct 2022)
How to Become a Software Developer - Nakov in Mongolia (Oct 2022)How to Become a Software Developer - Nakov in Mongolia (Oct 2022)
How to Become a Software Developer - Nakov in Mongolia (Oct 2022)
 
Blockchain and DeFi Overview (Nakov, Sept 2021)
Blockchain and DeFi Overview (Nakov, Sept 2021)Blockchain and DeFi Overview (Nakov, Sept 2021)
Blockchain and DeFi Overview (Nakov, Sept 2021)
 

Recently uploaded

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Recently uploaded (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

Java Foundations: Maps, Lambda and Stream API

  • 3. The Judge System Sending your Solutions for Automated Evaluation
  • 4. Testing Your Code in the Judge System  Test your code online in the SoftUni Judge system: https://judge.softuni.org/Contests/3294
  • 5. Associative Arrays, Lambda and Stream API Collections and Queries
  • 6. Table of Contents 1. Associative Arrays (Maps)  HashMap <key, value>  LinkedHashMap <key, value>  TreeMap <key, value> 2. Lambda Expressions 3. Java Stream API  Filtering  Mapping  Ordering
  • 7. Associative Arrays Collection of Key and Value Pairs
  • 8.  Associative arrays are arrays indexed by keys  Not by the numbers 0, 1, 2, … (like arrays)  Hold a set of pairs {key  value} Associative Arrays (Maps) 9 John Smith +1-555-8976 Lisa Smith +1-555-1234 Sam Doe +1-555-5030 Key Value
  • 9. Collections of Key and Value Pairs  HashMap<K, V>  Keys are unique  Uses a hash-table + list  LinkedHashMap<K, V>  Keys are unique  Keeps the keys in order of addition  TreeMap<K, V>  Keys are unique  Keeps its keys always sorted  Uses a balanced search tree 10
  • 10.  put(key, value) method  remove(key) method Built-In Methods 11 HashMap<String, Integer> airplanes = new HashMap<>(); airplanes.put("Boeing 737", 130); airplanes.remove("Boeing 737"); HashMap<String, Integer> airplanes = new HashMap<>(); airplanes.put("Boeing 737", 130); airplanes.put("Airbus A320", 150);
  • 11.  containsKey(key)  containsValue(value) – slow operation! Built-In methods (2) 12 HashMap<String, Integer> map = new HashMap<>(); map.put("Airbus A320", 150); System.out.println(map.containsValue(150)); //true System.out.println(map.containsValue(100)); //false HashMap<String, Integer> map = new HashMap<>(); map.put("Airbus A320", 150); if (map.containsKey("Airbus A320")) System.out.println("Airbus A320 key exists");
  • 12. HashMap: put() 13 HashMap<String, String> Key Value Hash Function Pesho 0881-123-987 Gosho 0881-123-789 Alice 0881-123-978
  • 13. HashMap: remove() 14 HashMap<String, String> Key Value Pesho Pesho Gosho 0881-123-987 0881-123-789 Alice 0881-123-978 Hash Function
  • 14. Pesho 0881-123-987 TreeMap<K, V> – Example 15 TreeMap <String, String> Key Value Alice +359-899-55-592 Comparator Function
  • 15. Map<String, Double> fruits = new LinkedHashMap<>(); fruits.put("banana", 2.20); fruits.put("kiwi", 4.50); for (Map.Entry<K, V> entry : fruits.entrySet()) { System.out.printf("%s -> %.2f%n", entry.getKey(), entry.getValue()); }  Iterate through objects of type Map.Entry<K, V>  Cannot modify the collection (read-only) Iterating Through Map 16 entry.getKey() -> fruit name entry.getValue() -> fruit price
  • 16.  Read a list of real numbers and print them in ascending order along with their number of occurrences Problem: Count Real Numbers 17 8 2 2 8 2 2 -> 3 8 -> 2 1 5 1 3 1 -> 2 3 -> 1 5 -> 1
  • 17. Solution: Count Real Numbers 18 double[] nums = Arrays.stream(sc.nextLine().split(" ")) .mapToDouble(Double::parseDouble).toArray(); Map<Double, Integer> counts = new TreeMap<>(); for (double num : nums) { if (!counts.containsKey(num)) counts.put(num, 0); counts.put(num, counts.get(num) + 1); } for (Map.Entry<Double, Integer> entry : counts.entrySet()) { DecimalFormat df = new DecimalFormat("#.#######"); System.out.printf("%s -> %d%n", df.format(entry.getKey()), entry.getValue()); } Overwrite the value
  • 18.  Read 2 * N lines of pairs word and synonym  Each word may have many synonyms Problem: Words Synonyms 19 3 cute adorable cute charming smart clever cute - adorable, charming smart - clever
  • 19. Solution: Word Synonyms 20 int n = Integer.parseInt(sc.nextLine()); Map<String, ArrayList<String>> words = new LinkedHashMap<>(); for (int i = 0; i < n; i++) { String word = sc.nextLine(); String synonym = sc.nextLine(); words.putIfAbsent(word, new ArrayList<>()); words.get(word).add(synonym); } // TODO: Print each word and synonyms Adding the key if it does not exist
  • 21. Lambda Functions  A lambda expression is an anonymous function containing expressions and statements  Lambda expressions  Use the lambda operator ->  Read as "goes to"  The left side specifies the input parameters  The right side holds the expression or statement 22 (a -> a > 5)
  • 22.  Lambda functions are inline methods (functions) that take input parameters and return values: Lambda Functions 23 x -> x / 2 static int func(int x) { return x / 2; } static boolean func(int x) { return x != 0; } x -> x != 0 () -> 42 static int func() { return 42; }
  • 23. Stream API Traversing and Querying Collections
  • 24.  min() - finds the smallest element in a collection:  max() - finds the largest element in a collection: Processing Arrays with Stream API (1) 25 int min = Arrays.stream(new int[]{15, 25, 35}).min().getAsInt(); int max = Arrays.stream(new int[]{15, 25, 35}).max().getAsInt(); 35 int min = Arrays.stream(new int[]{15, 25, 35}).min().orElse(2); int min = Arrays.stream(new int[]{}).min().orElse(2); // 2 15
  • 25.  sum() - finds the sum of all elements in a collection:  average() - finds the average of all elements: Processing Arrays with Stream API (2) 26 int sum = Arrays.stream(new int[]{15, 25, 35}).sum(); double avg = Arrays.stream(new int[]{15, 25, 35}) .average().getAsDouble(); 75 25.0
  • 26.  min() Processing Collections with Stream API (1) 27 ArrayList<Integer> nums = new ArrayList<>() {{ add(15); add(25); add(35); }}; int min = nums.stream().mapToInt(Integer::intValue) .min().getAsInt(); int min = nums.stream() .min(Integer::compareTo).get(); 15
  • 27.  max()  sum() Processing Collections with Stream API (2) 28 int max = nums.stream().mapToInt(Integer::intValue) .max().getAsInt(); int max = nums.stream() .max(Integer::compareTo).get(); int sum = nums.stream() .mapToInt(Integer::intValue).sum(); 35 75
  • 28.  average() Processing Collections with Stream API (3) 29 double avg = nums.stream() .mapToInt(Integer::intValue) .average() .getAsDouble(); 25.0
  • 29.  map() - manipulates elements in a collection: Manipulating Collections 30 String[] words = {"abc", "def", "geh", "yyy"}; words = Arrays.stream(words) .map(w -> w + "yyy") .toArray(String[]::new); //abcyyy, defyyy, gehyyy, yyyyyy int[] nums = Arrays.stream(sc.nextLine().split(" ")) .mapToInt(e -> Integer.parseInt(e)) .toArray(); Parse each element to Integer
  • 30.  Using toArray(), toList() to convert collections: Converting Collections 31 int[] nums = Arrays.stream(sc.nextLine().split(" ")) .mapToInt(e -> Integer.parseInt(e)) .toArray(); List<Integer> nums = Arrays.stream(sc.nextLine() .split(" ")) .map(e -> Integer.parseInt(e)) .collect(Collectors.toList());
  • 31.  Using filter() Filtering Collections 32 int[] nums = Arrays.stream(sc.nextLine().split(" ")) .mapToInt(e -> Integer.parseInt(e)) .filter(n -> n > 0) .toArray();
  • 32.  Read a string array  Print only words which length is even Problem: Word Filter 33 kiwi orange banana apple kiwi orange banana pizza cake pasta chips cake
  • 33. Solution: Word Filter 34 String[] words = Arrays.stream(sc.nextLine().split(" ")) .filter(w -> w.length() % 2 == 0) .toArray(String[]::new); for (String word : words) { System.out.println(word); }
  • 34.  Using sorted() to sort collections: Sorting Collections 35 nums = nums.stream() .sorted((n1, n2) -> n1.compareTo(n2)) .collect(Collectors.toList()); nums = nums.stream() .sorted((n1, n2) -> n2.compareTo(n1)) .collect(Collectors.toList()); Ascending (Natural) Order Descending Order
  • 35.  Using sorted() to sort collections by multiple criteria: Sorting Collections by Multiple Criteria 36 Map<Integer, String> products = new HashMap<>(); products.entrySet() .stream() .sorted((e1, e2) -> { int res = e2.getValue().compareTo(e1.getValue()); if (res == 0) res = e1.getKey().compareTo(e2.getKey()); return res; }) .forEach(e -> System.out.println(e.getKey() + " " + e.getValue())); Second criteria Terminates the stream
  • 36. Using Functional forEach (1) 37 Map<String, ArrayList<Integer>> arr = new HashMap<>(); arr.entrySet().stream() .sorted((a, b) -> { if (a.getKey().compareTo(b.getKey()) == 0) { int sumFirst = a.getValue().stream().mapToInt(x -> x).sum(); int sumSecond = b.getValue().stream().mapToInt(x -> x).sum(); return sumFirst - sumSecond; } return b.getKey().compareTo(a.getKey()); }) Second criteria Descending sorting
  • 37. Using Functional forEach (2) 38 .forEach(pair -> { System.out.println("Key: " + pair.getKey()); System.out.print("Value: "); pair.getValue().sort((a, b) -> a.compareTo(b)); for (int num : pair.getValue()) { System.out.printf("%d ", num); } System.out.println(); });
  • 38.  Read a list of numbers  Print largest 3, if there are less than 3, print all of them Problem: Largest 3 Numbers 39 10 30 15 20 50 5 50 30 20 1 2 3 3 2 1 20 30 30 20
  • 39. Solution: Largest 3 Numbers 40 List<Integer> nums = Arrays .stream(sc.nextLine().split(" ")) .map(e -> Integer.parseInt(e)) .sorted((n1, n2) -> n2.compareTo(n1)) .limit(3) .collect(Collectors.toList()); for (int num : nums) { System.out.print(num + " "); }
  • 40.  …  …  … Summary  Maps hold {key  value} pairs  Keyset holds a set of unique keys  Values hold a collection of values  Iterating over a map takes the entries as Map.Entry<K, V>  Lambda and Stream API help collection processing
  • 41.  …  …  … Next Steps  Join the SoftUni "Learn To Code" Community  Access the Free Coding Lessons  Get Help from the Mentors  Meet the Other Learners https://softuni.org

Editor's Notes

  1. Hello, I am Svetlin Nakov from SoftUni (the Software University). Together with my colleague George Georgiev, we continue teaching this free Java Foundations course, which covers important concepts from Java programming, such as arrays, lists, maps, methods, strings, classes, objects and exceptions, and prepares you for the "Java Foundations" official exam from Oracle. In this lesson your instructor George will explain the concept of associative arrays (or maps), which hold key-to-value mappings. He will demonstrate through live code examples how to use standard API classes, such as Map, HashMap and TreeMap, to work with maps in Java. Just after the maps, the instructor will explain the concept of lambda expressions and how to define and use lambda functions in Java through the arrow operator. Lambda expressions are important in Java programming, because they enable processing and querying Java collections, using the Java Stream API. In this lesson, the instructor will demonstrate the power of the Stream API, and how to map, filter and sort sequences of elements (such as arrays, lists and maps), how to extract subsequences, how to convert a sequence to array or list and many other operations over sequences. Let's learn maps, lambda functions and the Stream API in Java through live coding examples, and later solve some hands-on exercises to gain practical experience. Are you ready? Let's start!
  2. Before the start, I would like to introduce your course instructors: Svetlin Nakov and George Georgiev, who are experienced Java developers, senior software engineers and inspirational tech trainers. They have spent thousands of hours teaching programming and software technologies and are top trainers from SoftUni. I am sure you will like how they teach programming.
  3. Most of this course will be taught by George Georgiev, who is a senior software engineer with many years of experience with Java, JavaScript and C++. George enjoys teaching programming very much and is one of the top trainers at the Software University, having delivered over 300 technical training sessions on the topics of data structures and algorithms, Java essentials, Java fundamentals, C++ programming, C# development and many others. I have no doubt you will benefit greatly from his lessons, as he always does his best to explain the most challenging concepts in a simple and fun way.
  4. Before we dive into the course, I want to show you the SoftUni judge system, where you can get instant feedback for your exercise solutions. SoftUni Judge is an automated system for code evaluation. You just send your code for a certain coding problem and the system will tell you whether your solution is correct or not and what exactly is missing or wrong. I am sure you will love the judge system, once you start using it!
  5. // Solution to problem "01. Student Information". import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String name = sc.nextLine(); int age = Integer.parseInt(sc.nextLine()); double grade = Double.parseDouble(sc.nextLine()); System.out.printf("Name: %s, Age: %d, Grade: %.2f", name, age, grade); } }
  6. Now it’s time to start the lesson. Your instructor George will explain the concept of maps in Java and how to use the HashMap and TreeMap classes. He will teach you how to use lambda expressions and the Java Stream API to map, filter and sort lists, arrays and other collections. Let’s start.
  7. © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.
  8. © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.
  9. © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.
  10. Did you like this lesson? Do you want more? Join the learners' community at softuni.org. Subscribe to my YouTube channel to get more free video tutorials on coding and software development. Get free access to the practical exercises and the automated judge system for this coding lesson. Get free help from mentors and meet other learners. Join now! It's free. SOFTUNI.ORG