Monthly Archives: April 2020

Find the third largest number in an array in Java

Find the third largest number in an array in Java: In this article, learn how to find the third largest number in an array in java.

Answer: 40 Explanation:  1. Sort the numbers in the array by comparing the adjacent numbers. Means if an array is having three numbers i.e 2,1,3, then  compare 2… Read More »

random string java

In this tutorial, you are going to learn how to generate a random string in java. We are using randomAlphabetic method present in RandomStringUtils class of Apache to generate a random string java. apache.commons.lang3.RandomStringUtils.randomAlphabetic: Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of Latin… Read More »

StringUtils isAlphanumeric

StringUtils isAlphanumeric checks if the CharSequence contains only Unicode letters or digits. null will return false. An empty CharSequence (length()=0) will return false. Examples: StringUtils.isAlphanumeric (null) = false StringUtils.isAlphanumeric (“”) = false StringUtils.isAlphanumeric (” “) = false StringUtils.isAlphanumeric (“abc”) = true StringUtils.isAlphanumeric (“ab c”) = false StringUtils.isAlphanumeric (“ab2c”) = true StringUtils.isAlphanumeric (“ab-c”) = false Parameters:… Read More »

StringUtils getDigits method

StringUtils getDigits method checks if a String str contains Unicode digits, if yes then concatenate all the digits in str and return it as a String. An empty (“”) String will be returned if no digits found in str. Examples: StringUtils.getDigits (null) = null StringUtils.getDigits (“”) = “” StringUtils.getDigits (“abc”) = “” StringUtils.getDigits (“1000$”) =… Read More »

StringUtils lowercase

StringUtils lowercase method converts a string to lowercase. Examples:

Note: As described in the documentation for String.toLowerCase(), the result of this method is affected by the current locale. For platform-independent case transformations, the method lowerCase(String, Locale) should be used with a specific locale (e.g. Locale.ENGLISH). Summary: From this method we have learned how to… Read More »

StringUtils indexOf

StringUtils indexOf method returns the index of the first occurrence of the specified character from a string. If it doesn’t find the character then it returns -1. A null CharSequence will return -1. Syntax: StringUtils.indexOf (CharSequence seq, CharSequence searchSeq); Parameters: seq the CharSequence to check, may be null searchSeq the CharSequence to find, may be… Read More »

StringUtils upperCase

StringUtils upperCase method converts a string to uppercase. Parameters: str the String to upper case, may be null Returns: the upper cased String, null if null String input StringUtils uppercase Examples:

Below are the methods provided in StringUtils class and these are all null safe. Equals/Compare: It compares whether two given strings are equal or not. EqualsAny: Compares… Read More »

StringUtils endsWith

StringUtils endsWith method checks if a string ends with a specified character/suffix and return true otherwise returns false. nulls are handled without exceptions. Two null references are considered to be equal. The comparison is case sensitive. Examples:

  Below are the methods provided in StringUtils class and these are all null safe. Equals/Compare: It compares whether two… Read More »

StringUtils startsWith

This method checks if a string starts with a specified character/prefix. nulls are handled without exceptions. Two null references are considered to be equal. The comparison is case sensitive. Examples:

   

StringUtils trim

It removes spaces from both ends of the string. Examples:

Basically, it removes control characters (char <= 32) from both ends of this String, handling null by returning null. The String is trimmed using String.trim(). Trim removes start and end characters <= 32. Other trim methods: trimToEmpty trimToNull 1. trimToEmpty: This method removes control… Read More »

StringUtils isBlank

This method checks if a char sequence is empty (“”), null or whitespace(s) only. Examples:

 

StringUtils isEmpty

This method checks if given char sequence is empty (“”) or null. It returns true if the char sequence is empty or null. Else it returns false. Examples:

 

StringUtils equalsAny method

StringUtils equalsAny method is used to compare a string with n number of strings at a time. equalsAny method is present in the lang3 package i.e import org.apache.commons.lang3.StringUtils. If you use import org.apache.commons.lang.StringUtils in your code, equalsAny method won’t be available. Compares given string to a CharSequences of searchStrings and returns true if the string is… Read More »

StringUtils equals method

It compares two CharSequences and returns true if they represent equal sequences of characters otherwise returns false. It is also used to handles nulls. Two null references are considered equal and hence it returns true. The comparison is case sensitive. Examples:

 

StringUtils

StringUtils class is provided by Apache. Standard libraries present in Java doesn’t provide all the methods required for manipulation so Apache Commons Lang provides these extra methods. Below are the methods provided in StringUtils class and these are all null safe. Equals/Compare: It compares whether two given strings are equal or not. EqualsAny: Compares if… Read More »

git

In this article, you can learn different errors faced while working with git. Git errors: 1. fatal: refusing to merge unrelated histories Solution: If you get this error, you can use the command “–allow-unrelated-histories” to solve it. Syntax:

2. file path too long error Solution: Above error can be resolved by using below command.… Read More »