Common methods of vector classes in Java

Source: Internet
Author: User

Vector class is the implementation of the list interface, so the method of inheritance is not here to say

Https://www.cnblogs.com/xiaostudy/p/9503199.html

Public void add(int index, E Element)

The element element is added from the position of the index, and subsequent elements are shifted back one bit.

Public Boolean addall(int index, Collection<? extends E> C)

Add all the elements from the C collection starting at the index position, and the subsequent elements move backward through the c.size () bit.

Public void addelement(E obj)

Adding an element after the collection, regardless of the type of the element, adds the return value of his ToString ().

public int capacity()

Returns the current capacity of this vector, not the number of elements.

View the vector class's constructors

Visible, the parameterless constructor is the default 10 capacity size

Public void copyinto(Object[] anarray)

Copy the elements in the collection into the Anarray array

public E elementat(int index)

Returns the element of the index position

Public Enumeration<E> elements()

Returns an enumeration of collections

Public void ensurecapacity(int mincapacity)

Increase the capacity of the collection, if the increased capacity is less than 10, then invalid, that is, increase the capacity of 10 times times

Public void insertelementat(E obj, int index)

Inserts an OBJ element in the specified index position

Public void removeallelements()

Delete all the elements of the collection, and set the capacity to 0, as with the clear () method, the clear bottom layer is also used with the Removeallelements () method

The measured capacity is not 0, it's time to look for problems.

Public void setSize(int newSize)

Sets the size of the collection to NewSize, and if newsize is greater than the number of collection elements, then NULL is added later, and if NewSize is less than the number of collection elements, the newsize element is reserved

Public void trimtosize()

The capacity size of the collection, if the number of collection elements equals the size of the capacity, then there is no change, if the number of collections is less than the capacity size, then the capacity is set to the number of elements

Common methods of vector classes in Java

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.