Java Learning--arraylist Use method: List of the main implementation class

Source: Internet
Author: User

* New additions to the list in relation to collection
* void Add (int index, Objectele): Adds an element at the specified index position index ele
Boolean addall (int index, Collection eles)
Object get (int index): Gets the element of the specified index
Object Remove (int index): Deletes the element at the specified index position
Object Set (int index, Objectele): Sets the element at the specified index position to Ele
int IndexOf (OBJECTOBJ): Returns the position of the first occurrence of obj in the collection. If not, return-1
int LastIndexOf (OBJECTOBJ): Returns the position of the last occurrence of obj in the collection. No, return-1
List sublist (int fromIndex, Inttoindex): Returns the left-hand side from FromIndex to the end of Toindex opens a sub list

List Common methods: Add (Object obj) Delete (remove) change (set (Intindex,object obj))
(Get (int index)) plug (add (int index, Object ele)) Length (size ())

1 @Test2      Public voidTestList2 () {3List List =NewArrayList ();4List.add (123);5List.add (456);6List.add (NewString ("AA"));7List.add (NewString ("GG"));8List.add (456);9System.out.println (List.indexof (456));TenSystem.out.println (List.lastindexof (456)); OneSystem.out.println (List.indexof (123) = = List.lastindexof (123)); ASystem.out.println (List.indexof (444)); -         -List list1 = list.sublist (0, 3); the System.out.println (list1); -     } -     - @Test +      Public voidTestList1 () { -List List =NewArrayList (); +List.add (123); AList.add (456); atList.add (NewString ("AA")); -List.add (NewString ("GG")); - System.out.println (list); -List.add (0,555); - System.out.println (list); -Object obj = list.get (1); in System.out.println (obj); -List.remove (0); toSystem.out.println (List.get (0)); +List.set (0, 111); -System.out.println (List.get (0)); the}

Java Learning--arraylist Use method: List of the main implementation class

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.