Mahesh Parahar has Published 154 Articles

How to convert a Java list to a set?

Mahesh Parahar

Mahesh Parahar

Updated on 09-May-2022 11:59:46

299 Views

A list can be converted to a set object using Set constructor. The resultant set will elliminate any duplicate entry present in the list and will contains only the unique values.Set set = new HashSet(list);Or we can use set.addAll() method to add all the elements of the list to the ... Read More

Can we convert a Java list to array?

Mahesh Parahar

Mahesh Parahar

Updated on 09-May-2022 11:57:35

571 Views

The List provides two methods to convert a List into Array.1. Use toArray() method without parameter.Object[] toArray()ReturnsAn array containing all of the elements in this list in proper sequence.2. Use toArray() with array. T[] toArray(T[] a)Parametersa  − The array into which the elements of this list are to be stored, ... Read More

How to check the Java list size?

Mahesh Parahar

Mahesh Parahar

Updated on 09-May-2022 11:47:11

849 Views

List provides a method size() to check the current size of the list.Syntaxint size()Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.ReturnsThe number of elements in this list.ExampleThe following example shows how to get size of a list using size() method.package ... 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

931 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

929 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

257 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

462 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

Advertisements