
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

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 to their indices).Type ParameterE − The runtime type of the element.Parametersindex − Index at which the specified element is to be inserted.e − Element to be inserted to this list.ThrowsUnsupportedOperationException − If the add operation is not supported by this listClassCastException − If the class of the specified element prevents it ... Read More

16K+ Views
Yes, we can insert null values into a list easily using its add() method. In case of List implementation does not support null, then it will thrown a NullPointerException List is an interface in Java that extends the Collection interface and provides a way to store an ordered collection of elements. It allows us to store duplicate elements, and it also maintains the order of insertion. The List interface is implemented by classes such as ArrayList, LinkedList, and Vector. Null Values in a Java List In Java, a List can contain null values. The List interface allows for the insertion of ... Read More

700 Views
In this article, we will learn how to insert an element at a specific index in a Java list. For example, we have a fruit list by certain order and we want to insert a new fruit at a specific index in the list. Following are the ways to insert an element at a specific index in a Java list: Using add() Method Using ListIterator Using Stream API Using add() Method The add() method of the the list interface helps us to insert an element at ... Read More

8K+ Views
In this article, we will learn how to insert all elements from one list into another in Java. This is a general operation we perform when working with lists while solving problems in Java. We will cover the following methods to insert all elements from one list into another: Using addAll() Method Using For Loop Using Stream API Using ListIterator Using addAll() Method We can add all elements of one list into another list easily using its addAll() method. This method appends all of the elements in the specified collection to the end of this list, in the ... Read More

923 Views
List Interface is a collection in Java that is used for storing elements in a sequence. It also allows us to save duplicates as well as null values. In this article, we will learn how to empty a list in Java. Following are the ways to empty a list in Java: Using clear() Method Using removeAll() Method Using clear() Method The clear() method of the List interface is used to remove all elements from the list. It removes all the elements but returns nothing. Following is the syntax of the ... Read More

886 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 is not supported by this listClassCastException − If the class of the specified element prevents it from being added to this listNullPointerException − If the specified element is null and this list does not permit null elementsIllegalArgumentException − If some property of this element prevents it from being added to ... Read More

266 Views
In this article, we will learn how we can use multithreading in Ruby. We will take a couple of examples, where we will spawn two new threads and then perform some concurrent operations on them. In Ruby, we can create a new thread with the help of the Thread.new() function.Example 1Take a look at the following example to understand the nature of multiple threads and how they are executed in Ruby.#!/usr/bin/ruby # first method def First_Method a = 0 while a

417 Views
Ruby's integer class is the foundation for the two concrete classes that represent whole numbers. Bignum and Fixnum are these concrete classes. Bignum holds the integer value that is outside the range of Fixnum, which is displayed in the native machine word.There are a variety of methods in the integer class that can be used to perform various tasks. Numeric class has a subclass called Integer. Let's check some of the useful methods that are available in the integer class in Ruby.to_i methodThe to_i method is used to return an integer. Consider the code shown belowExampleConsider the code shown below.num ... Read More

1K+ Views
In Ruby, there are four different types of variables that we can declare −Local VariablesInstance VariablesClass VariablesGlobal VariablesAn Instance variable has a name that starts with the @ symbol. It should be noted that the contents of an instance variable are only restricted to the object which itself refers to.An important point to note about the instance variable in Ruby is that, even if we have two separate objects that belong to the same class, we are allowed to have different values for their instance variables.Instance Variable Characteristics in RubyBefore checking how to use instance variables in Ruby, let's understand ... Read More

1K+ Views
In Ruby, when we are using the include keyword, we are importing a module code, but we aren't allowed to access the methods of the imported modules with the class directly because it basically gets imported as a subclass for the superclass.On the other hand, when we are using the extend keyword in Ruby, we are importing the module code but the methods are imported as class methods. If we try to access the methods that we imported with the instance of the class, the compiler will throw an error.Now let's use these two keywords in a Ruby code to ... Read More