- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 10102 Articles for Object Oriented Programming

56 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

37 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

67 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

58 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

120 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

214 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

117 Views
JDK 1.5 introduced a new for loop known as foreach loop or enhanced for loop, which enables you to traverse the complete array sequentially without using an index variable. Examplepublic class ArrayUsingForEach { public static void main(String[] args) { double[] myList = {1.9, 2.9, 3.4, 3.5}; // Print all the array elements for (double element: myList) { System.out.println(element); } } }Output1.9 2.9 3.4 3.5

229 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

163 Views
This article will help you understand what the continue statement in Java Programming language is. Continue Statement The statement continue, is just the opposite of Break statement. As soon as the continue statement is executed in a loop, the control skips rest of the statements for that value and resumes for the next iteration. Syntax while (condition){ Statement 1; _________________; _________________; if (another condition is true){ continue; } Statement 2; _________________; ... Read More

86 Views
This article will help you understand what the break statement in Java Programming language is. Break Statement Sometimes, it is needed to stop a look suddenly when a condition is satisfied. This can be done with the help of break statement. A break statement is used for unusual termination of a block. As soon as you apply a break statement, the control exits from the block (A set of statements under curly braces). Syntax for (condition){ execution continues if (another condition is true){ break; } ... Read More