Java basic Knowledge Enhancement collection Frame Note 25:vector's unique features

Source: Internet
Author: User

1. Vector- specific features :
(1) Add function
public void addelement (Object obj)--add ()
(2) Get function
Public Object elementat (int index)--get ()
Public enumeration elements ()--iterator Iterator ()

Enumeration (Interface):

Boolean hasmoreelements ()--Hasnext ()
Object nextelement ()--Next ()

2. code example:

1  Packagecn.itcast_02;2 3 Importjava.util.Enumeration;4 ImportJava.util.Vector;5 6 /*7 * Unique features of vector:8 * 1: Add features9 * public void addelement (Object obj)--Add ()Ten * 2: Get features One * Public Object elementat (int index)--get () A * Public enumeration elements ()--Iterator Iterator () - * Boolean hasmoreelements () Hasnext () - * Object nextelement () Next () the  *  - * Reasons for JDK Upgrade: - * A: Security - * B: Efficiency + * C: Simplified writing -  */ +  Public classVectordemo { A      Public Static voidMain (string[] args) { at         //To create a collection object -Vector v =NewVector (); -  -         //Add features -V.addelement ("Hello"); -V.addelement ("World"); inV.addelement ("Java"); -  to         //Traverse +          for(intx = 0; x < V.size (); X + +) { -String s =(String) v.elementat (x); the System.out.println (s); *         } $ Panax NotoginsengSystem.out.println ("------------------"); -  theEnumeration en = V.elements ();//returns an object of the implementation class +          while(En.hasmoreelements ()) { AString s =(String) en.nextelement (); the System.out.println (s); +         } -     } $}

The results are as follows:

Java basic Knowledge Enhancement collection Frame Note 25:vector's unique features

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.