ArrayList methods used
System.Collections.ArrayList class is a special array. By adding and deleting elements can be dynamically changed the length of the array.
1. Advantages
1. Automatically change the size of support functions
2. Flexible elements can be inserted
3. Flexible elements can be deleted
2. Limitations
With an array of general than, the rate on Chaisuo
3. Add elements
1. PublicvirtualintAdd (objectvalue);
Will be added to the ArrayList object to the end
ArrayListaList = newArrayList ();
AList.Add ( "a");
AList.Add ( "b");
AList.Add ( "c");
AList.Add ( "d");
AList.Add ( "e");
Says abcde
2. PublicvirtualvoidInsert (intindex, objectvalue);
ArrayList element will be inserted into the designated Index
ArrayListaList = newArrayList ();
AList.Add ( "a");
AList.Add ( "b");
AList.Add ( "c");
AList.Add ( "d");
AList.Add ( "e");
AList.Insert (0, "aa");
Results for aaabcde
3. PublicvirtualvoidInsertRange (intindex, ICollectionc);
Will bring together elements inserted in a specified index Department ArrayList
ArrayListaList = newArrayList ();
AList.Add ( "a");
AList.Add ( "b");
AList.Add ( "c");
AList.Add ( "d");
AList.Add ( "e");
ArrayListlist2 = newArrayList ();
List2.Add (the "tt");
List2.Add ( "ttt");
AList.InsertRange (2, list2);
Results for abtttttcde
4. Delete
A) publicvirtualvoidRemove (objectobj);
Remove from ArrayList targeted first match, the attention is the first
ArrayListaList = newArrayList ();
AList.Add ( "a");
AList.Add ( "b");
AList.Add ( "c");
AList.Add ( "d");
AList.Add ( "e");
AList.Remove ( "a");
Results for bcde
2.publicvirtualvoidRemoveAt (intindex);
Remove ArrayList designated elements of the index
AList.Add ( "a");
AList.Add ( "b");
AList.Add ( "c");
AList.Add ( "d");
AList.Add ( "e");
AList.RemoveAt (0);
Results for bcde
3. PublicvirtualvoidRemoveRange (intindex, intcount);
Remove from ArrayList a range of elements. Index said that indexing, the index count from the beginning that the number of
AList.Add ( "a");
AList.Add ( "b");
AList.Add ( "c");
AList.Add ( "d");
AList.Add ( "e");
AList.RemoveRange (1,3);
Results ae
4. PublicvirtualvoidClear ();
Remove from ArrayList all the elements.
5. Sorting
A) publicvirtualvoidSort ();
The ArrayList or a part of it sort of elements.
ArrayListaList = newArrayList ();
AList.Add ( "e");
AList.Add ( "a");
AList.Add ( "b");
AList.Add ( "c");
AList.Add ( "d");
DropDownList1.DataSource = aList; / / DropDownListDropDownList1;
DropDownList1.DataBind ();
Results for eabcd
ArrayListaList = newArrayList ();
AList.Add ( "a");
AList.Add ( "b");
AList.Add ( "c");
AList.Add ( "d");
AList.Add ( "e");
AList.Sort ();// sort
DropDownList1.DataSource = aList; / / DropDownListDropDownList1;
DropDownList1.DataBind ();
Results for abcde
B) publicvirtualvoidReverse ();
ArrayList or it will be part of the elements in reverse order.
ArrayListaList = newArrayList ();
AList.Add ( "a");
AList.Add ( "b");
AList.Add ( "c");
AList.Add ( "d");
AList.Add ( "e");
AList.Reverse ();// reversal
DropDownList1.DataSource = aList; / / DropDownListDropDownList1;
DropDownList1.DataBind ();
Results for edcba
6. View
A) publicvirtualintIndexOf (object);
B) publicvirtualintIndexOf (object, int);
C) publicvirtualintIndexOf (object, int, int);
Back to ArrayList or a part of it in a value of the first match of the index from scratch. There is no return -1.
ArrayListaList = newArrayList ();
AList.Add ( "a");
AList.Add ( "b");
AList.Add ( "c");
AList.Add ( "d");
AList.Add ( "e");
IntnIndex = aList.IndexOf ( "a ");// 1
NIndex = aList.IndexOf ( "p ");// not found, -1
D) publicvirtualintLastIndexOf (object);
E) publicvirtualintLastIndexOf (object, int);
F) publicvirtualintLastIndexOf (object, int, int);
Back to ArrayList or a part of it in a value of the final match of the index from scratch.
ArrayListaList = newArrayList ();
AList.Add ( "a");
AList.Add ( "b");
AList.Add ( "with a ");// 0
AList.Add ( "d");
AList.Add ( "e");
IntnIndex = aList.LastIndexOf ( "a ");// value of 2 rather than 0
G) publicvirtualboolContains (objectitem);
In determining whether a particular element in the ArrayList. Include returns true, otherwise returns false
7. Other
1. PublicvirtualintCapacity (get; set;)
Acquire or set up ArrayList can contain several elements.
2. PublicvirtualintCount (get;)
Get ArrayList actually contains several elements.
Capacity is ArrayList few elements can be stored. Count ArrayList is included in the actual number of elements. Capacity is always greater than or equal to Count. If the added element, more than Capacity Count, the capacity of the list will be automatically re-allocated through an array of internal doubled.
If the value of Capacity Explicit settings, also need an array of internal re-allocation to accommodate the designated capacity. If Explicit Capacity was set to 0, the common language runtime library will be set to the default of its capacity. Default capacity of 16.
Clear in the call, Count 0, and this is the default Capacity cut capacity 16, rather than 0
3. PublicvirtualvoidTrimToSize ();
ArrayList capacity will be set in the actual number of elements.
If we do not add to the list of new elements, this method can be used on the smallest of the memory system overhead.
To completely remove all the elements of the list, please call before calling TrimToSize Clear method. Amputated empty ArrayList ArrayList capacity will be installed to the default capacity, rather than zero.
ArrayListaList = newArrayList ();
AList.Add ( "a");
AList.Add ( "b");
AList.Add ( "c");
AList.Add ( "d");
AList.Add ( "e ");// Count = 5, Capacity = 16,
AList.TrimToSize ();// Count = Capacity = 5;
Tags: ArrayList, java ArrayList






