The VECTOR class provides a function of achieving a growing array, with more elements to join, the array changes. After deleting some elements, the array becomes smaller.
Vector has three constructor:
Public Vector (int InitialCapacity) public vector (int initialcapacity) public vector ()
The vector is running an initial storage capacity initialcapacity, and the storage capacity is incrementally increased in the CapacityInCrement variable. The initial storage capacity and CapacityInCrement can be defined in the constructor of the Vector. The second constructor only creates an initial storage capacity. The third constructor does not specify whether the initial storage capacity is not specified in CapacityInCrement.
The access method provided by the Vector class supports similar array operations and computational operations with the Vector size. The calculation of similar arrays allows the vector to increase, delete, and insert elements. They also allow the contents of the test vector and retrieve the specified element, and the calculations associated with the size allow determination byte size and the elements in the vector.
For example, for example, it is now used, deleted, interpolated, and exemplified:
AddElement (Object Obj)
Add the components to the tail of the tail, at the same time, 1, vector capacity than before 1
INSERTETELEMENTAT (Object Obj, Int Index)
Add the components to the findings, this subsequent content moves 1 unit
SETELEMENTAT (Object Obj, Int Index)
Add the components to the findings, the content here is replaced.
RemoveEleMent (Object Obj) removes the contents of this component.
RemoveAllelements () removes all components in the vector, the vector size is 0.
E.g:
Import java.lang.system; import java.util.vector; import java.util.emumeration; public class avector {public static void main (string args []) {Vector v = new vector (); v.addelement ("ONE "); V.addelement (" two "); v.Insertelementat (" zero ", 0); v.insertelementat (" OOP ", 3); v.selectionatat (" three " , 3); V.SETELEMENTAT ("FOUR", 4); v.removeAllelements ();}} Vector changes:
Changes in Vector:
1. One 2. ONE 3. One 4. Zero 5.Zero 6. Zero 7. Zero 8. Two Two One One One ONE Three THREE Three Three Four In addition, Vector played in the parameter transfer Flavored effect.
There is a Canvas and a (Panel) in the applet, while the user wants to enter information, passes the parameters to Canvas based on this information, at this time, in Java, in the interfab, Use a vector to pass these parameters in an interface. In addition, this method can be used in one class to another class parameter. E.g:
Import java.util.vectorinterface code = new vector ();} Show mathematics information display mathematical information
VECTOR (0) deposits the student number
VECTOR (1) Depository in Panel When users choose their own content in TextField and Choice, the value is passed through the event response to the vector vector. If you are in the Panel class:
Public void codepanel extends panel {public void init () {**. Textfield s = new textfield (); choice c = new choice (); c. additem ("language"); C.Additem ("mathematics"); C .additem ("politics"); add (s); add (c); **} public boolean handleevent (Event.ID == Event.Action_event) {if (event.target.instanceof textfield) {CodeResult.selementat (s.getText (), 0);} else if (event.target intenceof choice) {codeResult.selectionatat (new integer (c.getSelected "), 1);}}}} Student ID and Social Search No. (0 are Chinese, 1 is math, 2 is politics). At this time, the vector number and subject index quotation marks (0 are languages, 1 is politics).
This value is obtained in Canvas, public class codecanvas extends can{ public void code {} public void point {string str; int T; str = (string) codeResult.Elementat (0); t = (new integer) (1) .tostring ())). INTVALUE (); if (t == 0) {display language information} else if (t == 1) {display mathematical information} else if (t == 2) {display politics Information}}}
This article refers to the advertisement address: http://www.donews.net/a7fei/services/trackbackbacks/131536.aspx