# Learning Objectives And Outcomes Of Vectors

788 Words4 Pages
LESSON 9: VECTORS
LEARNING OBJECTIVES AND OUTCOMES
• Introduction
• Vectors
• Wrapper Classes
INTRODUCTION
Vectors are commonly used instead of arrays.They expand automatically when new data is added to them. Vectors can hold only Objects and not primitive types like int. It implements a dynamic array. It is similar to ArrayList, but has two differences:
Vector is synchronized.
• Vector contains many legacy methods that are not the part of a collections framework.
VECTORS
Vector class is used to create a generic dynamic array known as vector. It can hold objects of any type and any number. They are created in following manner: Vector intVect = new Vector(); //declaring without size Vector list = new Vector(3); // declaring with size
There are following advantages of Vectors over array:
1. It can store a list of objects that may vary in size.
2. It is more convenient to store objects.
3. Addition and removal of objects are easy.
Some of the Vector constructors are:
Vector( )
Vector(int size)
Vector(int size, int incr)
Vector(Collection a)
The first statement will create a default vector of size 10. The second statement creates a vector whose initial capacity is specified by size. The third statement will create a vector whose initial capacity is specified by size and whose increment is specified by incr. The increment specifies the number of elements to allocate each time that a vector is resized upward. The fourth statement will create a vector that contains the