Working with Simple Groups in Java Regular Expressions

Vikyath Ram
Updated on 30-Jun-2020 08:29:44

201 Views

Multiple characters can be treated as a single unit using groups in Java regular expressions. The method java.time.Matcher.group() is used to find the subsequence in the input sequence string that is a match to the required pattern.A program that demonstrates groups in Java regular expressions is given as follows −Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {    public static void main(String args[]) {       Pattern p = Pattern.compile("\w\d");       Matcher m = p.matcher("I am f9");       System.out.println("The input string is: I am f9");       System.out.println("The Regex is: \w\d");     ... Read More

PHP rand() Function

Malhar Lathkar
Updated on 30-Jun-2020 08:29:10

344 Views

Definition and UsageThe rand() function returns an integer using pseudo random genaration technique. default range is between 0 and platform specific getrandmax(). On 64 bit Windows OS, it is 2147483647. The rand() function can be called without arguments (in which case the default range will be used) or by specifying min and max parameters.This function always returns an integer.Syntaxrand ( void ) : int rand ( int $min , int $max ) : intParametersSr.NoParameter & Description1minlower limit of range to return a number from. Default is 02maxUpper limit of range to return a number from. Default is getrandmax()Return ValuesPHP rand() ... Read More

Create a Read-Only Collection in Java

Arushi
Updated on 30-Jun-2020 08:28:36

205 Views

An example of a read-only collection can be an unmodifiable ArrayList. The unmodifiable view of the specified ArrayList can be obtained by using the method java.util.Collections.unmodifiableList(). This method has a single parameter i.e. the ArrayList and it returns the unmodifiable view of that ArrayList.A program that demonstrates this is given as follows −Example Live Demoimport java.util.ArrayList; import java.util.Collections; import java.util.List; public class Demo {    public static void main(String args[]) throws Exception {       List aList = new ArrayList();       aList.add("Apple");       aList.add("Mango");       aList.add("Guava");       aList.add("Orange");       aList.add("Peach"); ... Read More

Enumerate Through Vector Elements in Java

Rishi Raj
Updated on 30-Jun-2020 08:25:07

737 Views

The Vector elements can be traversed using the Enumeration interface. The method hasMoreElements( ) returns true if there are more elements to be enumerated and false if there are no more elements to be enumerated. The method nextElement( ) returns the next object in the enumeration.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Enumeration; import java.util.Vector; public class Demo {    public static void main(String args[]) {       Vector vec = new Vector();       vec.add(7);       vec.add(3);       vec.add(5);       vec.add(9);       vec.add(2);     ... Read More

Loop Through Vector Elements Using an Iterator in Java

Jai Janardhan
Updated on 30-Jun-2020 08:22:40

2K+ Views

An Iterator can be used to loop through the Vector elements. The method hasNext( ) returns true if there are more elements in the Vector and false otherwise. The method next( ) returns the next element in the Vector and throws the exception NoSuchElementException if there is no next element.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Iterator; import java.util.Vector; public class Demo {    public static void main(String args[]) {       Vector vec = new Vector();       vec.add(4);       vec.add(1);       vec.add(3);       vec.add(9);     ... Read More

Loop Through Vector Elements Using ListIterator in Java

Arushi
Updated on 30-Jun-2020 08:21:33

190 Views

A ListIterator can be used to traverse the elements in the forward direction as well as the reverse direction in a Vector. The method hasNext( ) in ListIterator returns true if there are more elements in the Vector while traversing in the forward direction and false otherwise. The method next( ) returns the next element in the Vector and advances the cursor position.A program that demonstrates this is given as follows −Exampleimport java.util.ListIterator; import java.util.Vector; public class Demo {    public static void main(String args[]) {       Vector vec = new Vector();       vec.add(3);     ... Read More

Find the Maximum Element of a Vector in Java

Arushi
Updated on 30-Jun-2020 08:20:22

1K+ Views

The maximum element of a Vector can be obtained using the java.util.Collections.max() method. This method contains a single parameter i.e. the Vector whose maximum element is determined and it returns the maximum element from the Vector.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Collections; import java.util.Vector; public class Demo {    public static void main(String args[]) {       Vector vec = new Vector();       vec.add(7);       vec.add(3);       vec.add(9);       vec.add(5);       vec.add(8);       System.out.println("The Vector elements are: " + vec);     ... Read More

Find Minimum Element of a Vector in Java

Jai Janardhan
Updated on 30-Jun-2020 08:19:28

530 Views

The minimum element of a Vector can be obtained using the java.util.Collections.min() method. This method contains a single parameter i.e. the Vector whose minimum element is determined and it returns the minimum element from the Vector.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Collections; import java.util.Vector; public class Demo {    public static void main(String args[]) {       Vector vec = new Vector();       vec.add(7);       vec.add(3);       vec.add(9);       vec.add(5);       vec.add(8);       System.out.println("The Vector elements are: " + vec);     ... Read More

Convert a Vector to an Array in Java

Vikyath Ram
Updated on 30-Jun-2020 08:18:22

1K+ Views

A Vector can be converted into an Array using the java.util.Vector.toArray() method. This method requires no parameters and it returns an Array that contains all the elements of the Vector in the correct order.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Vector; public class Demo {    public static void main(String args[]) {       Vector vec = new Vector();       vec.add(7);       vec.add(3);       vec.add(5);       vec.add(2);       vec.add(8);       Object[] arr = vec.toArray();       System.out.println("The Array elements are: ");   ... Read More

Clone a Vector in Java

Rishi Raj
Updated on 30-Jun-2020 08:16:58

306 Views

A Vector can be cloned using the java.util.Vector.clone() method. This method does not take any parameters but returns a clone of the specified Vector instance as an object.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Vector; public class Demo {    public static void main(String args[]) {       Vector vec1 = new Vector();       vec1.add(7);       vec1.add(3);       vec1.add(5);       vec1.add(9);       vec1.add(2);       Vector vec2 = (Vector) vec1.clone();       System.out.println("The Vector vec1 elements are: " + vec1);       ... Read More

Advertisements