Dark Horse Programmer _java Collection using

Source: Internet
Author: User

-------<a href= "http://www.itheima.com" target= "blank" >android training </a> <a href= "/http/ Www.itheima.com "target=" blank ">java training </a>, look forward to communicating with you! ----------

I. Concept of a collection
    • 1. What is a collection
      • A collection is a container that is variable in length and can store objects of any type. The base data type can also be loaded into the collection, but the inside is automatically boxed into the wrapper class object before it is stored in the collection's
Two. Classification of collections
  • 1.collection
    • list: repeatable, with storage order, indexed
      • arraylist array implementation, adding and deleting slow, Find Fast
      • linkedlist chain list implementation, delete quickly, find slow
      • vector array implementation, The same principle as ArrayList, but thread safe
    • set: Non-repeatable, inconsistent access order, no index
      • hashset
      • treeset
      • linkedhashset
  • 2.Map
    • HashMap
    • TreeMap
    • Hashtable
    • Linkedhashmap
Three. Common methods for collections
  • 1. Common methods
    • add (Object obj) adds an element to the collection, adds to the last position
    • get (int index) gets the element at the specified position in the collection
    • size () gets the length of the collection
    • add (int index, Object obj) adds an element to the collection, adds it to the specified position
    • set ( int index, Object obj replaces the element at the specified position in the collection with the
    • remove (int index) Deletes the element at the specified position in the collection
    • remove (object obj) deletes the Obj object contained in the collection ( Iterate through the elements in the collection if the incoming element equals an element, call the Remove method, note: The corner label is--)
  • 2. Iteration Collection
    • A.for Loop: A size ()-1 that loops from 0 to the collection, one for each
    • B. Iterator: Call the iterator () method to get the iterator, use Hasnext () to determine if the next element is included, and use Next () to get the next element
    • C. Enhanced for Loop: for (type variable name: container) {loop Body} The number of elements in the container executes how many times the loop body is executed, each time the loop variable points to a different element in the container
  • 3. Issues that are removed during iteration
    • A.for Loop: Delete the loop variable after deletion because the subsequent element will move forward--
    • B. iterators: You must use Remove () in iterator to delete an element otherwise an exception will be thrown
    • C. Enhanced for loop: Cannot delete

Dark Horse Programmer _java Collection using

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.