Monthly Archives: May 2020

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 »