Understanding java-9.2 container Types from scratch

Source: Internet
Author: User

In this chapter we will discuss the types of containers.

Containers are generally divided into two categories:

Collection: A separate sequence of objects.

Includes: List-saves objects in order, set-objects in order, queue-queues

MAP: "Key-Value" object or dictionary or associative array.

Package Com.ray.ch09;import Java.util.arraylist;import Java.util.hashmap;import Java.util.hashset;public class Test { Private arraylist<string> list = new arraylist<string> ();p rivate hashset<string> set = new hashset< String> ();p rivate hashmap<string, string> map = new hashmap<string, string> ();p ublic Test () {for (int i = 0 ; I < 10; i++) {List.add ("a");} for (int i = 0; i < i++) {Set.add ("a");} for (int i = 0; i < i++) {map.put ("name" + I, "a");}} Public arraylist<string> getList () {return list;} public void setlist (arraylist<string> list) {this.list = list;} Public hashset<string> Getset () {return set;} public void Setset (hashset<string> set) {This.set = set;} Public hashmap<string, String> Getmap () {return map;} public void Setmap (hashmap<string, string> map) {this.map = map;} public static void Main (string[] args) {test test = new test (); System.out.println ("--------list--------"); Arraylist<string> List = Test.getlist (); for (int i = 0; i < list.size (); i++) {System.out.println (List.get (i));} System.out.println ("--------set--------"); hashset<string> set = Test.getset (); for (String Str:set) {System.out.println (str);} SYSTEM.OUT.PRINTLN ("--------map--------"); hashmap<string, string> map = Test.getmap (); for (int i = 0; i <; i++) {System.out.println (Map.get ("name" + i)) ;}}}


Output:

--------List--------
A
A
A
A
A
A
A
A
A
A
--------Set--------
A
--------Map--------
A
A
A
A
A
A
A
A
A
A
The above code shows the features of list, set, and map, which are the three common container types.

Summary: This section briefly describes the two types of containers.

This chapter is here, thank you.

-----------------------------------

Directory


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Understanding java-9.2 container Types from scratch

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.