Category: Exams of Oracle

Implementing the java.util.Comparator Interface – Object ComparisonImplementing the java.util.Comparator Interface – Object Comparison

14.5 Implementing the java.util.Comparator<E> Interface The java.util.Comparator<E> interface is a functional interface and is designated as such with the @FunctionalInterface annotation in the Java SE API documentation— in other words, [...]

Implementing the java.lang.Comparable Interface 3 – Object ComparisonImplementing the java.lang.Comparable Interface 3 – Object Comparison

Output from the program: Click here to view code image class VersionNumberUnsorted array: [(3.49.1), (8.19.81), (2.48.28), (10.23.78), (9.1.1)]Unsorted list:  [(3.49.1), (8.19.81), (2.48.28), (10.23.78), (9.1.1)]Unsorted map: {(10.23.78)=5000, (3.49.1)=2000, (8.19.81)=3000, (9.1.1)=6000,               (2.48.28)=4000}Sorted [...]

Implementing the java.util.Comparator Interface 3 – Object ComparisonImplementing the java.util.Comparator Interface 3 – Object Comparison

Output from the program: Click here to view code image List before sorting:  [(3.49.1), (8.19.81), (2.48.28), (10.23.78), (9.1.1)]List after sorting according to reverse natural ordering:  [(10.23.78), (9.1.1), (8.19.81), (3.49.1), (2.48.28)]Binary [...]

Implementing the java.util.Comparator Interface 2 – Object ComparisonImplementing the java.util.Comparator Interface 2 – Object Comparison

The String class implements the Comparable<E> interface, providing an implementation of the compareTo() method. The compareTo() method defines the natural ordering for strings, which is lexicographical. The natural ordering is [...]

Contexts for Defining Lambda Expressions – Functional-Style ProgrammingContexts for Defining Lambda Expressions – Functional-Style Programming

13.14 Contexts for Defining Lambda Expressions In this section, we summarize the main contexts that can provide target types for lambda expressions and method references. Declaration and Assignment Statements Ample [...]