Friday, May 29, 2020

Java String offsetByCodePoints​() Method Example

1. Java String offsetByCodePoints​() Method Overview

offsetByCodePoints​() method returns the index within this String that is offset from the given index by codePointOffset code points.
Unpaired surrogates within the text range given by index and codePointOffset count as one code point each.

Java String API offsetByCodePoints​() Method Example

1.1 Syntax


Here is the full syntax for this method and part of java.lang package.

public int offsetByCodePoints​(int index, int codePointOffset)

Article on Java Package

Java 8 Stream allMatch() Method Example

1. Introduction


In this tutorial, We will see the example program on Java 8 Stream allMatch() method. allMatch() method checks whether all elements of Stream is matched to the given predicate then it returns true. Otherwise returns false.

Predicate is nothing but a condition.

This is called Terminal Operation because this is executed at the end of the stream. That means Stream is closed after the execution of allMatch() method.


Java 8 Stream allMatch() Method Example


Java 8 Stream allMatch()


Monday, May 25, 2020

Optional ofNullable() method (With Examples)

1. Introduction


In this tutorial, We'll learn Optional ofNullable() example on how to create new Java 8 Optional object for any value or null value. Optional is part of java.util package.

Java 8 Optional ofNullable() Method Example


API Note: Returns an Optional describing the given value, if non-null, otherwise returns an empty Optional.

Friday, May 22, 2020

Java Program To Insertion Sort With Example

1. Introduction


Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much more efficient than Bubble Sort and less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.

We can implement  Insertion sort using iterative and recursive approach. We will do in this post using Iterative approach. It is easy to understand when compared to recursive.

The insertion sorts repeatedly scans the list of items, each time inserting the item in the unordered sequence into its correct position.

Java Program to Bubble Sort 

Java Program To Insertion Sort With Example

Java 8 Optional orElseGet() Example

1. Introduction

In this tutorial, We'll learn java 8 Optional API orElseGet() method examples and where to use.

2. Syntax


public T orElseGet(Supplier<? extends T> other)

Return the value if present, otherwise invoke other and return the result of that invocation. This method takes the Supplier Functional Interface.

if the Supplier is null, it throws NullPointerException.

Filtering with Optional in Java 8

Java 8 Optional orElseGet() Example

Thursday, May 21, 2020

CSS Property: font-weight Examples

CSS font-weight Property


The CSS property "font-weight" sets how thick or thin characters in text should be displayed. This provides variant thicker types.

CSS Property font-weight

Tuesday, May 19, 2020

Jackson API @JsonAnyGetter Annotation - Map Example

1. Introduction


In this Jackson Annotation Series, You'll be learning @JsonAnyGetter annotation and example program to demonstrate @JsonAnyGetter annotation with Map Example in Jackson API.

Jackson API is mainly integrated with Java tech stack.

Mainly @JsonAnyGetter is used on Map<String, String> property which holds the additional properties which are apart from the normal properties.

Please note that @ JsonAnyGetter is a method level annotation and can not be used on the filed level. If you use so on field level will cause a compile-time error.

This is the first annotation in our series.


Jackson API @JsonAnyGetter Annotation - Map Example