package com.howtodoinjava.demo.serialization; import java.io.*; import java.util.logging.Logger; public class DemoClass implements java.io.Serializable { private static final long serialVersionUID = 4L; //Default serial version uid private static final String fileName = "DemoClassBytes.ser"; /...
Function<String,String>toUpperCase=x->x.toUpperCase();pets.stream().map(x->toUpperCase.apply(x)).forEach(System.out::println); Copy When you define afunctionyou have to specify the input and output types. In our example, both are strings. That’s why the first line starts withFunction<S...
We have twocharvariables,char1has a lowercase character whilechar2have an uppercase character. To convertchar1to an uppercase character, we call thetoUpperCase()static method from theCharacterclass and passchar1as an argument. The same goes to convertchar2to lowercase; we call thetoLowerCase()...
In JavaScript, you can use theArray.map()method to iterate over all elements and then use the string methods to change the case of the elements. Here is an example that demonstrates how to use theString.toUpperCase()method along withArray.map()to uppercase all elements in an array: const...
const str = "JavaScript Courses" const newStr = str.replace('JavaScript', 'Java') console.log(newStr) // Java Courses To perform a global search to replace all occurrences of a string, you can use a regular expression with a global modifier:const str = "Mr. Red owns a red bike and...
1 Observable<Integer> observable = Observable.fromCallable(() -> 1); Create an Observable using “just” operator 1 Observable<Integer> observable = Observable.just(1, 2, 3); Posted in RxJava Guava Function Example: How to use function with Lists.transform()Posted...
java streams – npi ea (cat=java streams) since its introduction in java 8, the stream api has become a staple of java development. the basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use. but these can also be overused and fall into ...
TheApache Commons Langpackage provides many helper utilities related to string manipulation in Java. Because it is a third party, it must first be added as a dependency in the project. We can use theRandomStringUtils classto generate the random string This class has three methods that can give...
Since we have to capitalize first letter here, we will use str.charAt(0) to extract first letter from the String. 1 2 3 4 5 const str = 'java2blog'; const firstChar = str.charAt(0); console.log(firstChar); Output: J toUpperCase() toUpperCase() function returns all input charact...
JavaString.endsWith()is used to check the suffix of a given string. It verifies if the given string ends with the argument string or not. To check if a string starts with a specified substring, usestartsWith()method. Note that using the regular expression is also an effective way tocheck...