Found 34485 Articles for Programming

What does the method removeAllElements() do in java?

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

92 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

60 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 specify repetitions Regex in Python?

Pranav Indukuri
Updated on 08-Nov-2022 11:14:42

1K+ Views

A regular expression is a series of characters that allows you to discover a string or a set of strings using a search pattern. Regular expressions are sometimes known as RegEx. In Python, the re module is used to work with regular expressions. We can use repetitions in regular expression to match the string in python. To make repetitions possible in regular expression, we indicate the number of times the character is repeating in {}. Using search() function In the following example, we match ‘TTTTPPP’ string which is present in the string ‘TTTTTTPPPPPPPPPPPP’. Here, we have used T{4}P{3} to match ... 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

How to match pattern over multiple lines in Python?

Pranav Indukuri
Updated on 08-Nov-2022 11:13:17

10K+ Views

A regular expression is a group of characters that allows you to use a search pattern to find a string or a set of strings. RegEx is another name for regular expressions. The re module in Python is used to work with regular expressions. To match the pattern over multiple lines in python by using regular expression, we use .* regular expression. Here, , indicates paragraph tag in HTML5. Implies zero or more occurrence of characters. . is a special character that matches all characters, including newline characters with the help of re.DOTALL flag. Generally, in regular ... Read More

Advertisements