Mahesh Parahar has Published 191 Articles

How to check if Java list contains an element or not?

Mahesh Parahar

Mahesh Parahar

Updated on 09-May-2022 11:44:40

4K+ Views

List provides a method contains() to check if list contains that element or not. It utilizes equals() method so we need to override the equals() method in the element type.Syntaxboolean contains(Object o)Returns true if this list contains the specified element. More formally, returns true if and only if this list ... Read More

How do I add multiple items to a Java ArrayList in single statement?

Mahesh Parahar

Mahesh Parahar

Updated on 09-May-2022 11:30:00

3K+ Views

We can utilize Arrays.asList() method to get a List of specified elements in a single statement.Syntaxpublic static List asList(T... a)Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.)Type ParameterT  − The runtime type of the array.Parametersa  − The array ... Read More

How do I insert an item between two items in a list in Java?

Mahesh Parahar

Mahesh Parahar

Updated on 09-May-2022 11:26:55

2K+ Views

We can insert element between two items of an array list easily using its add() method.Syntaxvoid add(int index, E element)Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one ... Read More

How do I add an element to an array list in Java?

Mahesh Parahar

Mahesh Parahar

Updated on 09-May-2022 08:51:37

881 Views

SolutionWe can add element to an array list easily using its add() method.Syntaxboolean add(E e)Appends the specified element to the end of this list.Type ParameterE  − The runtime type of the element to be added.Parameterse  − Element to be appended to this listReturnsIt returns true.ThrowsUnsupportedOperationException  − If the add operation ... Read More

Adobe Photoshop - Photo & Design Software

Mahesh Parahar

Mahesh Parahar

Updated on 14-Feb-2022 12:00:07

2K+ Views

Adobe Photoshop is the most popular photo editor and designing software. Adobe Photoshop is available for Windows, macOS and iPAD. Adobe Photoshop is very easy to use and provides many useful features required for image editing and designing. Adobe Photoshop is an industry standard in photo editing and digital art. ... Read More

Difference between :focus and :active selector in HTML

Mahesh Parahar

Mahesh Parahar

Updated on 21-Dec-2021 07:28:36

836 Views

:focus:focus selector is used to applying a required style when a form element got to focus like button, link, input box. An element can get focus using mouse or using tab key. A focus remains on the element until another element gets focus.:active:active selector is used to indicating that an ... Read More

Difference between sums of odd position and even position nodes of a Binary Tree in Java

Mahesh Parahar

Mahesh Parahar

Updated on 16-May-2020 14:54:17

222 Views

Problem StatementWith a given binary tree, write a program to find the difference between sum of nodes at odd position and even position. Assume root at level 0, odd position, left/right child of root at level 2, left child at odd position and right child at even position and so ... Read More

Difference between sums of odd level and even level nodes of a Binary Tree in Java

Mahesh Parahar

Mahesh Parahar

Updated on 16-May-2020 14:50:36

399 Views

Problem StatementWith a given binary tree, write a program to find the difference between sum of nodes at odd level and even level. Assume root at level 1, left/right child of root at level 2 and so on.Example        5       /   \     ... Read More

Difference between sums of odd and even digits.

Mahesh Parahar

Mahesh Parahar

Updated on 16-May-2020 14:49:21

543 Views

Problem StatementWith a given long integer n, write a program to find the difference between sum of the odd digits and even digits to be 0 or not. Index starts from 0.Examplen = 1212112 Sum of odd position elements = 2 + 2 + 1 = 5 Sum of ... Read More

Difference between sum of the squares of and square of sum first n natural numbers.

Mahesh Parahar

Mahesh Parahar

Updated on 16-May-2020 14:45:24

962 Views

Problem StatementWith a given number n, write a program to find the difference between sum of the squares of and square of sum first n natural numbers.Examplen = 3 Squares of first three numbers = 3x3 + 2x2 + 1x1 = 9 + 4 + 1 = 14 Squares ... Read More

Advertisements