Java Collection Framework + application Tips

Source: Internet
Author: User

First, General introduction

1. Interface

Collective interface in collections:

Provides the implementation of various algorithms, such as sorting and traversal of sets.

List is not the only, orderly

Set is the only, orderly

1.ArrayList not unique sequential traverse efficiency is high

2.LinkedList is highly efficient when inserted and deleted using a link

ALT + S + R Generate Set,get method

ALT +/Build constructor method

Add to

Lis.add (DOG1);

Lis.add (DOG2);

The object is added here

Lis.size () defines the length of the array

Lis.remove (0); Delete an object with an index number of 0

Lis.remove (DOG0); Delete by the specified object name

2.hashset-1

3.Set

The set interface stores a unique, unordered set of objects

HashSet is a common implementation class for set interfaces

A reference to a set that holds an object

4.Iterator

How to traverse a set collection

Method One

Implementing traversal via iterator iterator

1. Get the iterator () method of the Iterator:collection interface

Methods of iterator

--boolean Hasnext (): Determine if there is another accessible element

--object Next (): Returns the next element to be accessed

Method Two

Enhanced for-loop

5.HashMap

Map countries = new HashMap ();

Countries.get ("key value");

Countries.containskey ("key value"); Returns the Boolean type

Countries.containsvalue ("corresponding value"); Returns the Boolean type

Delete

Countries.remove ("FR");

Traverse

System.out.println (Countries.keyset ());

System.out.println (Countries.values ());

SYSTEM.OUT.PRINTLN (countries);

Empty

Countries.clear ()

To see if it is empty

IsEmpty ()

Vector and ArrayList

How to traverse a collection in a map

Java Collection Framework + application Tips

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.