>arrays
Basic array
1. The common array is generated from the main () function, and the index of the array subscript cannot exceed the range of 0 to int
2. ArrayIndexOutOfBoundsException exception occurs when a program attempts to access the first or last data of an array.
(equivalent to Linked list)
3. Unfortunately, the array does not have Java source code. It is an ordered collection of object objects.
Declaration/Initialization
1. The type of the array has a base type, the object type, and the declaration for the array only needs to be added []
2. Can be int[] test, int []test, int test[] three forms.
3. The definition of an array must be declared in the number. Arrays are usually defined using loops or assignments.
Array of primitive type/object type
An array of primitive types maintains a sequential list of data, while object data exists in the object, and the array simply refers to the address of the object.
Multidimensional arrays
1. Like an array reference object, it is assumed that a multidimensional array is required to maintain multiple contiguous arrays.
2. The initialization of multidimensional arrays also specifies the length. For example, a 2-dimensional array, the 1th subscript indicates how many arrays are maintained, and the 2nd subscript represents maintenance
The number inside the array.
3. The value of a multidimensional array must be determined by multiple dimensions together.
Initialization of variables:When the type array specifies the number, memory is assigned to the memory array
and give the default variable, generally according to the type specified, such as int specified as 0,double to 0.0d,string is null;
to pass an array to the method and get the return value:
When passing a parameter, the system passes the array reference to the method, so you can change its value in the array.
Copying and cloing arrays:
Because the array is already fixed in initialization, you must use replication or cloning when you want to scale the arrays.
The system provides a tool method for copy, which provides the target of the source, the starting position and the copy length;
Throw arrayindexoutofboundsexception when data length is not enough to replicate
System.arraycopy (original,0, resultarray,0,original.length);
The system also provides a copy method, Array.clone (), to achieve replication.
In an array of types, a copy is a copy of a value, whereas in an object array, only a shallow copy of the object is made;
array references and equality judgments:
> When a variable refers to an array, such as a reference arrray1, then assigning a to the variable b,b also references array1.
> When two objects refer to an array at the same time, it is judged that they can use a==b; when two objects pass
Clone copy to get an array, then they reference different memory address, can only use Equals ();
Arrays and strings:
In C, the char[] array is always used to represent a string, whereas in Java, an array can be exchanged with strings.
String1.tobytearray () Converts a string into an array;
New String (byte[]) to create a string;
>the Vector Classes
----Vector----
1. Create vectors can specify initial capacity and increase, or you can wrap another list, such as:
Vector v=new Victor (arrays.aslist (array));
2.Vector follows the standard of the queue
Can be added to the end of the queue with Add (obj)/addelement ().
You can add the index location by index Add (index,obj)/insertelement (Obj,index)
You can also add a collection queue to the end of AddAll (list);
3. Because the vector cannot add the original type, in the new version of the JDK, the system will automatically boxing for us;
Vector using ToString ();
4. Remove the vector to
Removes the Remove (obj)/removeelementat (index) by reference;
Removes the Remove (index)/removeelementat (index) by index;
By deleting part RemoveAll (list)/removerange (from,to);
Delete all Clear ()/removeallelement ();
Keep Collection selected to delete other Retainall (list)
5. Replace set (Index,obj)/setelement (Obj,index)
6. View/Set Queue size ()/setsize ()
7. Storage capacity: capacity is used to cope with the frequent increase or decrease of dynamic queue, if the queue capacity is too small, it should be increased
The queue is preceded by ensurecapacity (int mincapacity), assuming that the capacity is not general enough
Increase the capacity by 1 time; unlike size (), the size represents the current number, the capacity represents how much can be put;
After the queue operation is complete, you can call TrimToSize () to optimize the space reduction;
Invariance of 8.Vector:
Suppose there is a variable that is read only and provides unmodifiablelist (v) to prevent changes in collections;
9. Enumeration of elements
Public enumeration elements ();
while (E.hasmoreelements ()) {
Process (E.nextelement ());
}
Extended Abstractlist
Iterator i = V.iterator ();
while (I.hasnext ()) {
Process (E.next ());
}
10. Iterative values for multi-dimensional vectors:
MyType o = (MyType) ((Vector) Vector.elementat (3)). ElementAt (2);
11. Test vector elements:
Judgment exists: contains (obj)/containsall (list);
Index: indexOf (obj) If there are 2 indexes that get the 1th of the order
Reverse index: lastIndexOf (obj) as on reverse
12.Copy and Clone
Call Clone () direct copy or Copyinto (array) to convert the arrays before indirectly copying
13. Intercept the vector.
Public List sublist (int fromIndex, int toindex)
14. Use Equals () to determine whether the vector content is equal;
Advanced Java-Collections (1)