Organization of Java object groups: vector vectors

Source: Internet
Author: User
Tags int size

Functions of vectors:

1. can store any object

2. Cannot store basic types of data, such as 39, unless the data is wrapped in a parcel class

3. Its capacity can be automatically expanded according to demand

4. Increase the efficiency of the element method if the capacity is not expanded

Way:

Vector myvector=new vector ()///initial capacity of 10

Vector myvector=new vector (int cap)//initial capacity is cap

Vector myvector=new Vector (Collection col)//using the elements of the collection Col to initialize, and if you col an array, you need to convert it to a list object first

Example: Vector myvector=new vector (arrays.aslist (col));

void Add (Object obj)//Adds the given parameter object to the last of the vector's original element

Boolean AddAll (colletion col)//Adds all elements in the collection class object to the recipient object of this method, returns true if the recipient's result is changed

int size ()//Returns the number of elements

Boolean isempty ()//Determine whether the vector is empty

Object get (int pos)//return element at specified position

void set (int pos,object obj)//Replace an object in the vector with the position pos

Boolean remove (Object obj)//deletes the first obj object found, returns true. False if not found

Objectremove (int pos)//remove element from a given position and return the object being removed

Boolean RemoveAll (Collection col)//Delete all objects in the vector that appear in Col, return true if the recipient's result is changed

void clear ()//delete all elements of a vector

Boolean contain (Object obj)//Determine whether the vector contains obj

Boolean containall (Collection col)//Determine whether the vector contains all the elements in Col

int indexOf (Object obj)//returns the position of obj at the first occurrence of the vector and returns 1 if it is not found

Enumeration elements ()//Returns the enumeration object for all elements in the vector, noting that this method cannot be used for ArrayList

Iterator iterator ()//Return iterator object for all elements in vector

Special Note: Object get (int pos)//Read position is the element of POS, because it returns an object, so it needs to be plastic (explicit conversion)

Cases:

for (int i=0;i<v.size (); i++)

Custmer c= (Custmer) v.get (i); Every object read from V needs to be explicitly converted before it can be used correctly.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.