Convert String to boolean in java

Convert String to boolean in java: In this tutorial, you are going to learn how to convert string to boolean in java. We can achieve it in two ways. 1 Boolean.parseBoolean() method 2 Boolean.valueOf() method Both the methods are null safe. It means if you pass a value other than true or false, it won’t throw null… Read More »

How to remove last element from an ArrayList in Java

How to remove last element from an ArrayList in Java: The ArrayList class is a resizable array and it can be found in the java.util package. We can remove the last element from an ArrayList using remove() method. 1 remove(int i) 2 remove(Object obj)   1. remove(int i) method: First get the size of the… Read More »

How to clear an ArrayList in Java

How to clear an ArrayList in Java: We can use java.util.List.clear() and removeAll() methods to clear elements from an ArrayList. 1. Empty an ArrayList using clear() method: Syntax:

It removes all of the elements from the list. The list will be empty after this call returns. Example:

Output:

  2. Empty an… Read More »

How to remove an element from ArrayList in Java

How to remove an element from ArrayList in Java: The ArrayList class is a resizable array and it can be found in the java.util package. We can remove an element from ArrayList in java using below methods. 1 Using remove() methods. 2. Using iterator.remove() method   1. remove() methods: ArraysList has provided two overloaded methods… Read More »

Python

Python is a popular programming language. It is used for software development. Python is used to handle big data and to perform complex operations. Python works on different platforms  like windows, mac, linux, raspberry pi. Python code is readable and it is similar to combination of english and mathematics. While loop in python:

Output:… Read More »

Arrays toString method in java

Returns a string representation of the contents of the specified array. If the array contains other arrays as elements, they are converted to strings by the Object.toString() method inherited from Object, which describes their identities rather than their contents.The value returned by this method is equal to the value that would be returned by Arrays.asList(a).toString(),… Read More »

Arrays sort in java

Arrays.sort() method in java is used to sort the elements in ascending or descending order. Sorts the specified array of objects into ascending order, according to the natural ordering of its elements. All elements in the array must implement the Comparable interface. Furthermore, all elements in the array must be mutually comparable (that is, e1.compareTo(e2)… Read More »

Arrays.equals() in java

Arrays.equals() method returns true if the two specified arrays of longs are equal to one another. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain the same elements… Read More »

Arrays deepEquals in java

Arrays deepEquals in java: It returns true if the two specified arrays are deeply equal to one another. Unlike the equals(Object[],Object[]) method, this method is appropriate for use with nested arrays of arbitrary depth.Two array references are considered deeply equal if both are null, or if they refer to arrays that contain the same number… Read More »

binary search in java

Searches the specified array for the specified object using the binary search algorithm. The array must be sorted into ascending order according to the natural ordering of its elements (as by the sort(Object[]) method) prior to making this call. If it is not sorted, the results are undefined. (If the array contains elements that are… Read More »

Arrays in Java

Arrays class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists.The methods in this class all throw a NullPointerException, if the specified array reference is null, except where noted. The documentation for the methods contained in this class… Read More »

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: