import reactor.core.publisher.Mono; class ReactiveJavaTutorial { public static void main(String[] args) { String dataFromMono = getMono().block(); System.out.println(“Data from Mono: ” + dataFromMono); } private static Mono getMono() { return Mono.fromSupplier(() -> { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } return “Hello!”; }); } } Output: Data from Mono: Hello! class ReactiveJavaTutorial { public…
Read More Extract Data from Mono in Java
import reactor.core.publisher.Mono; class ReactiveJavaTutorial { public static void main(String[] args) { // create a Mono Mono<String> mono = Mono.just(“Hello”); // subscribe to a Mono mono.subscribe(); } } import reactor.core.publisher.Mono; class ReactiveJavaTutorial { public static void main(String[] args) { // create a Mono Mono<String> mono = Mono.just(“Hello”); // subscribe to a Mono mono.subscribe(data -> System.out.println(data)); }…
Read More Subscribe to a Mono in Java Reactor
public static <T> Mono<T> just(T data) import reactor.core.publisher.Mono; class ReactiveJavaTutorial { public static void main(String[] args) { Mono<String> mono = Mono.just(“Hello”); } } import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; class ReactiveJavaTutorial { public static void main(String[] args) { Publisher<String> mono = Mono.just(“Hello”); } } import reactor.core.publisher.Mono; class ReactiveJavaTutorial { public static void main(String[] args) { // will…
Read More Create a Mono in Java Reactor
In the previous post, we covered a String to Date conversion. In this post, you will learn to convert LocalDate and LocalDateTime to String in Java. LocalDate and LocalDateTime are immutable date-time objects that represent a date and a date and time. Both of the examples below make use of java.time package. For more information about Java packages, check out our…
Read More Convert LocalDate and LocalDateTime to String in Java
In this lesson, you will learn to convert String to LocalDate and LocalDateTime objects. LocalDate and LocalDateTime are immutable date-time objects representing a date and a date and time. To convert String to one of the two Date objects, the provided String must represent a valid date or time according to ISO_LOCAL_DATE or ISO_LOCAL_DATE_TIME. Otherwise, a DateTimeParseException will…
Read More Convert String to Date in Java
We can convert boolean to String in Java using the following methods: String.valueOf() method Boolean.toString() method Convert boolean to String in Java using the String.valueOf() method There are multiple overloaded versions of the valueOf() method from the String class. We will use the one which accepts boolean. Example class Test { public static void main(String[] args)…
Read More Convert boolean to String in Java
Testing Java with JUnit & Mockito This video course is for beginners and you do not need to have any prior Unit testing knowledge to enrol into this course. The course covers JUnit 5 basics as well as advanced topics. You will also learn to use another very popular testing framework for Java called Mockito.…
Read More My Video Courses
To convert String to boolean in Java, you can use one of the following methods: Boolean.parseBoolean() method BooleanUtils.toBoolean() method Boolean.valueOf() method if we need a Boolean object instead of a primive Convert String to boolean in Java using the Boolean.parseBoolean() method With the parseBoolean(String s) method of the Boolean class, if we want to get…
Read More Convert Java String to boolean
In the previous lesson, we covered the conversion of Octal to Decimal. In this post, you will learn how to convert Decimal to Octal in Java. We can do that in the following ways: Using the Integer.toOctalString() method With a custom logic Convert Decimal to Octal in Java using the Integer.toOctalString() method Integer class has…
Read More Convert Decimal to Octal in Java
We can convert Octal to Decimal in Java in the following ways: Using the parseInt() method Using custom logic Convert Octal to Decimal in Java using the parseInt() method Integer class has a method parseInt(String s, int radix) that parses the String argument as a signed integer in the radix specified by the second argument. Example class Test…
Read More Convert Octal to Decimal in Java
To convert String to char in Java we can use the charAt() method of the String class. This method returns the char value at the specified index. Syntax public char charAt(int index) Example class Test { public static void main(String[] args) { char ch = “java”.charAt(1); // returns char ‘a’ System.out.println(“char: ” + ch); } }…
Read More Convert String to char in Java
We can convert float to String in Java using the following methods: String.valueOf() method Float.toString() method Convert float to String in Java using the String.valueOf() method There are multiple overloaded versions of the valueOf() method from the String class. We will use the one which accepts float. Example class Test { public static void main(String[] args)…
Read More Convert float to String in Java
We often have to extract some text that is a number. To perform some operations on that number, we must first convert it to the appropriate type. In this post, you will learn how to convert Java String to float data type. You can use the Float.parseFloat() method to parse Java String to float. public static…
Read More Convert Java String to Float
To convert int to double in Java, we just need to assign the int value to a double. That is called implicit type casting since we convert a smaller data type to a bigger one. Example class Test { public static void main(String[] args) { int num = 128; double d = num; System.out.println(d); } }…
Read More Convert int to double in Java
We need to perform a type casting to convert long to int in Java since we want to convert a higher data type to a lower one. Java type casting is the process of changing one data type into another. See the following example: class Test { public static void main(String[] args) { long l…
Read More Convert Long to Int in Java