Found 9321 Articles for Object Oriented Programming

What does the method removeAllElements() do in java?

Rishi Raj
Updated on 25-Feb-2020 10:07:20

89 Views

The removeAllElements() method is used to remove all components from this vector and sets its size to zero. This method is identical in functionality to the clear method.Exampleimport java.util.Vector; public class VectorDemo {    public static void main(String[] args) {       Vector vec = new Vector(4);       vec.add(4);       vec.add(3);       vec.add(2);       vec.add(1);       System.out.println("Added numbers are :- ");       for (Integer number : vec) {          System.out.println("Number = " + number);       }       System.out.println("Size of ... Read More

What does the method removeElementAt(int index) do in java?

George John
Updated on 30-Jul-2019 22:30:21

59 Views

The removeElementAt(int index) method is used to delete the component at the specified index. Each component in this vector with an index greater or equal to the specified index is shifted downward to have an index one smaller than the value it had previously and the size of this vector is decreased by 1. Example public class VectorDemo { public static void main(String[] args) { Vector vec = new Vector(4); vec.add(4); vec.add(3); ... Read More

What does the method lastElement() do in java?

Arushi
Updated on 25-Feb-2020 10:08:06

98 Views

The lastElement() method is used to return the last component of the vector.Exampleimport java.util.Vector; public class VectorDemo {    public static void main(String[] args) {       Vector vec = new Vector(4);       vec.add(4);       vec.add(3);       vec.add(2);       vec.add(1);       System.out.println("Last element: "+vec.lastElement());    } }OutputLast element: 1

What does the method firstElement() do in java?

Paul Richard
Updated on 25-Feb-2020 10:09:47

93 Views

The firstElement() method is used to return the first component (the item at index 0) of this vector.Exampleimport java.util.Vector; public class VectorDemo {    public static void main(String[] args) {       Vector vec = new Vector(4);       vec.add(4);       vec.add(3);       vec.add(2);       vec.add(1);       System.out.println("First element is :"+vec.firstElement());    } }OutputFirst element is :4

What does the method elementAt(int index) do in java?

Vikyath Ram
Updated on 30-Jul-2019 22:30:20

171 Views

The elementAt(int index) method is used to get the component at the specified index/location of the vector.Exampleimport java.util.Vector; public class VectorDemo {    public static void main(String[] args) {       Vector vec = new Vector(4);       vec.add(4);       vec.add(3);       vec.add(2);       vec.add(1);       System.out.println("Element at 1st position :- "+vec.elementAt(1));    } }OutputElement at 1st position :- 3

What does the method addElement(E obj) do in java?

Rishi Raj
Updated on 26-Feb-2020 06:10:20

286 Views

The addElement(E obj) method is used to add the specified component to the end of this vector and increasing its size by one. The capacity of this vector is increased if its size becomes greater than its capacity. This addElement() method is identical in functionality to the add(Object) method. The add() method returns true/false but the addElement() method does not return any value.Exampleimport java.util.Vector; public class VectorDemo {    public static void main(String[] args) {       Vector vec = new Vector(4);       vec.add(4);       vec.add(3);       vec.add(2);       vec.add(1);       System.out.println("Initial ... Read More

What is a switch case statement in Java and how to use it?

Johar Ali
Updated on 25-Feb-2020 09:34:41

317 Views

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.Syntaxswitch(expression) {    case value :       // Statements       break;    case value :       // Statements       break;    // You can have any number of case statements.    default :       // Statements }The following rules apply to a switch statement −The variable used in a switch statement can only be integers, convertible integers (byte, short, char), ... Read More

How to use ‘do while loop’ in Java?

Rahul Sharma
Updated on 25-Feb-2020 09:49:15

157 Views

A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.SyntaxFollowing is the syntax of a do...while loop −do {    // Statements }while(Boolean_expression);Notice that the Boolean expression appears at the end of the loop, so the statements in the loop execute once before the Boolean is tested.If the Boolean expression is true, the control jumps back up to do statement, and the statements in the loop execute again. This process repeats until the Boolean expression is false.Examplepublic class Test {    public static void main(String args[]) {   ... Read More

What is the difference between >> and >>> operators in Java?

Samual Sam
Updated on 30-Jul-2019 22:30:21

1K+ Views

>> Binary Right ShiftThe left operand value is moved right by the number of bits specified by the right operand.>>> Shift right zero fillThe left operand value is moved right by the number of bits specified by the right operand and shifted values are filled up with zeros.

What is dot operator in Java?

Debarpito Sarkar
Updated on 05-Sep-2022 10:27:17

5K+ Views

This article will help you understand what a dot operator in Java Programming language is. Before jumping into Dot Operator, let us revise about Operators. OPERATORS In computer programming we often need to perform some arithmetical or logical operations. In such circumstances, we need operators to perform these tasks. Thus, an Operator is basically a symbol or token, which performs arithmetical or logical operations and gives us meaningful result. The values involved in the operation are called Operands. Here is a basic Pictorial representation of Operators. Now, let us discuss the types of Operators available. TYPES OF OPERATORS There ... Read More

Advertisements