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