Java introduction (6) -- mutual conversion of set, basic data type, and reference data type, and mutual conversion of data type
Set:
1. HashMap ----> class
Overview: you can find the value through the key, the key is the key, and the values is the value.
Feature: unordered values can be duplicate keys. Duplicate keys are not allowed. If duplicate keys are repeated, the values will be overwritten.
Review: 10 // int num = 10;
"Jack" // String name = "jack ";
"Jack" "rose" // String [] names = {"jack", "rose "};
10 "jack" // object ----> class (int age; String name)
// HashMap key: value 10: "jack "\
1. Definition Syntax:
1) declare first and then initialize
// Declare a HashMap object
HashMap <Integer, String> map;
// Initialize map = new HashMap <> (); // recommended
Map = new HashMap <Integer, String> ();
Map = new HashMap ();
2). Declare and initialize at the same time
HashMap <Integer, String> map2 = new HashMap <> (); // recommended
HashMap <Integer, String> map3 = new HashMap <Integer, String> ();
HashMap <Integer, String> map4 = new HashMap ();
2. ArrayList ----> class
// The elements in the ordered (subscript starts from 0) can be repeated.
Length: String. length ();
Array. length;
Set:. size ();
3. system diagram of the Set
Single Column setCollection
Set:
HashSet
TreeSet
List:
ArrayList
Double row setMap:
HashMap
TreeMap
Additional knowledge:
// <> Generic
// Vernacular: restrict the Data Types of stored data
// The first String limits the Data Type of the key to the String type.
// The second String limits the Data Type of l value to String.
// The generic data type can only be the reference data type, not the basic data type. What if we want to write the basic data type?
// Packaging class:
// Overview: it is actually the packaging of the basic data type, that is, packaging the basic data type as the reference data type. After packaging it as the reference data type, you can create an object and call a method, it can also be used as a data type in the // generic
// HashMap <int, String> map3 = new HashMap ();
// Int basic data type -------> reference data type (packaging type) // int -------> Integer
// Package basic data types into reference data typesInt num = 10; Integer i1 = new Integer (num );
// If the conversion fails, the basic data type cannot be called. Objects of the Data Type (class) can be called.
String str = i1.toString (); System. out. println (str + 1); // 101
Integer i2 = Integer. valueOf (num); // The package is 10.
String str2 = i2.toString (); System. out. println (str2 + 2 );
//Convert the referenced data type to the basic data typeInt value = i2.intValue (); System. out. println (value + 1); // 11
// Package the basic data type into the referenced data type ----> automatically convert Integer i3 = 19; String str3 = i3.toString (); System. out. println (str3 + 3 );
// Convert the referenced data type to the basic data type ---> automatic conversion of int num3 = i3; System. out. println (num3 + 3); // 22
/* Reference Data Type of the basic data type *
Byte ----> Byte
Short ----> Short
Int -----> Integer
Long ------> Long
Float ------> Float
Double -----> Double
Char ----> Character
Boolean ----> Boolean */