- 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 34487 Articles for Programming
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
457 Views
All the elements of a vector can be replaced by a specific element using java.util.Collections.fill() method. This method requires two parameters i.e. the Vector and the element that replaces all the elements in the Vector. No value is returned by the Collections.fill() method.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(5); vec.add(7); vec.add(4); vec.add(1); ... Read More
![Jai Janardhan](https://www.tutorialspoint.com/assets/profiles/13513/profile/60_63529-1512538711.jpg)
497 Views
An element of a Vector can be searched using the method java.util.ArrayList.indexOf(). This method returns the index of the first occurrence of the element that is specified. If the element is not available in the Vector, then this method returns -1.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(5); vec.add(4); vec.add(1); vec.add(7); ... Read More
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
523 Views
An element in a Vector can be replaced at a specified index using the java.util.Vector.set() method. This method has two parameters i.e the index at which the Vector element is to be replaced and the element that it should be replaced with. Vector.set() method returns the element that was at the position specified at the index previously.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(5); vec.add(7); ... Read More
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
89 Views
A single element in the Vector can be removed using the java.util.Vector.remove() method. This method removes the element at the specified index in the Vector. It returns the element that was removed. Also after the element is removed from the specified index, the rest of the Vector elements are shifted to the left.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(5); vec.add(4); ... Read More
![Jai Janardhan](https://www.tutorialspoint.com/assets/profiles/13513/profile/60_63529-1512538711.jpg)
289 Views
A Vector can be cleared in Java using the method java.util.Vector.clear(). This method removes all the elements in the Vector. There are no parameters required by the Vector.clear() method and it returns no value.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(5); vec.add(4); vec.add(1); vec.add(3); vec.add(9); vec.add(6); vec.add(2); vec.add(8); System.out.println("The Vector elements are: " ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
341 Views
A Vector can be printed in a comma-delimited list, in index order and surrounded by square brackets ([]) by simply using System.out.println() along with the Vector 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 vec = new Vector(5); vec.add(4); vec.add(1); vec.add(3); vec.add(9); vec.add(6); System.out.println(vec); } }The output of the above program is as follows −[4, 1, 3, 9, 6]Now let us understand ... Read More
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
103 Views
The method java.time.Matcher.pattern() returns the pattern that is matched upon by the Matcher. This method accepts no parameters.A program that demonstrates the method Matcher.pattern() 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[]) { String regex = "Apple"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher("AppleIsAFruit"); System.out.println("Pattern: " + m.pattern()); } }The output of the above program is as follows −Pattern: AppleNow let us understand the above program.The pattern that is matched upon ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
10K+ Views
A class contains a constructor to initialize instance variables in Java. This constructor is called when the class object is created.A program that demonstrates this is given as follows −Example Live Democlass Student { private int rno; private String name; public Student(int r, String n) { rno = r; name = n; } public void display() { System.out.println("Roll Number: " + rno); System.out.println("Name: " + name); } } public class Demo { public static void main(String[] args) { Student ... Read More
![Jai Janardhan](https://www.tutorialspoint.com/assets/profiles/13513/profile/60_63529-1512538711.jpg)
130 Views
The elements of a Collection can be appended at the end of the Vector using the method java.util.Vector.addAll(). This method takes a single parameter i.e. the Collection whose elements are added to the Vector and it returns true if the Vector is changed.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); System.out.println("The Vector vec1 elements ... Read More
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
394 Views
Elements can be added in the middle of a Vector by using the java.util.Vector.insertElementAt() method. This method has two parameters i.e. the element that is to be inserted in the Vector and the index at which it is to be inserted. If there is an element already present at the index specified by Vector.insertElementAt() then that element and all subsequent elements shift to the right by one.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(5); ... Read More