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
Programming Articles - Page 623 of 3363
968 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
912 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
289 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
443 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
1K+ Views
In Ruby, we use the "or" keyword to return the logical difference between its two operands. In simple terms, we can say that a condition becomes True if both the operands are true."or" returns True if any one of the conditions/expressions is "true".It returns False only when all the conditions are "false".It should be noted that the or keyword is equivalent to the "||" logical operator, but it has lower precedence in Ruby.SyntaxThe syntax of the or keyword is shown below.Condition1 or Condition2Let's use the or keyword in a Ruby code and see how it works.Example 1Consider the code shown ... Read More
2K+ Views
In Ruby, we use the not keyword when we want to get an expression and then invert its Boolean value. In simple words, if an expression evaluates to True, then by using the not keyword, we will get False as the result of the expression.It can be said that the not keyword works like the "!" operator in Ruby, but the only difference between them is that the "!" operator has the highest precedence of all operators and the "not" operator has the lowest.SyntaxHere is the syntax of the not keyword in Rubynot expressionNow, let's take a couple of examples ... Read More
653 Views
Ruby provides a special keyword known as defined? that is used to determine if a particular object or data type is defined in Ruby or not.The defined? keyword will return a string describing its expression or argument, if the passed expression or argument is defined. It returns nil if the expression or the argument is not defined in Ruby.SyntaxThe syntax of the defined keyword in Ruby is given belowdefined? variable_nameNow, let's take a couple of examples to demonstrate how to use the defined keyword in Ruby.Example 1Consider the code shown below.# Declare the Variables programming = 2 ruby = programming ... Read More
673 Views
'and' Keyword in RubyIn Ruby, we use the "and" keyword to return True if both the operands are true, and False if one or more of the operands is false. It should be noted that the and keyword is equivalent to the && logical operator, but it has lower precedence in Ruby.SyntaxThe syntax of the and keyword is shown below.expression1 and expression2Let's use the and keyword in a Ruby code and see how it works.ExampleConsider the code shown below.variable1 = "sunshine" variable2 = "$un$h1ne" # Using and keyword if (variable1 == "sunshine" and variable2 == "$un$h1ne") puts "Learn ... Read More