JavaDay09--Notes(集合的接口与功能+常用类Math,Random,System,Runtime,Calendar)
2018-01-03 22:00
537 查看
一、collections
1.区别
set元素不可重复,无序
list元素可重复,有序
2.set集合的分类
(1)HashSet
方法:1.用算法算出存储索引hashCode(Object obj);;2.存入元素equals();)
效果:自动去重,散列形式
返回值:int型整数,对象的hashcode
TreeSet
(2)TreeSet
特点:对加入集合中的元素自动进行去重和排序,但是必须在重写的方法中编写排序规则
comparable<T>接口
int comparableTo();方法
if return 1;
else if return 1;
else return 0;
3.接口
4. 功能
动态存放多个对象
5. 例子
List<String> list=new ArrayList<String>();
Collections.addAll(list,"字符串1","字符串2",……);\\全部添加
Collections.add(list);\\添加
Collections.shuffle(list); \\打乱
Collections.reverse(list);\\反转
模拟栈数据结构(先进后出FILO)::
LinkedList<String> list=new LinkedList<String>();
list.push("字符串1");
list.push("字符串2");
list.pop();
list.pop();
\\输出为 字符串2 字符串1
模拟队列数据结构(先进先出FIFO):
list.add("字符串1");
list.add("字符串2");
list.removeFirst();
list.removeFirst();
\\输出为 字符串1 字符串2
遍历字符串类型的数组
for(int i=0;i<list.size();i++){
list.get(i)+" "; // List接口扩展法:get(int index)方法
for(String str:list){
str+" "; // List加强for循环遍历
二、常用类
1. Math类
常用静态方法
2. Random类
public int nextInt(int bound)
返回从0(包含)到bound(不包含)的一个“伪随机” 整数值。
public boolean nextBoolean()
返回一个“伪随机”的boolean值
3. System类
public static void arraycopy(Object src,intsrcPos,Objectdest,intdestPos,int
length)
public static void exit(int status)
public static long currentTimeMillis()
*final不能被继承,不能被实例化(private 私有化)
4. Runtime类
totalMemory();
当前内存总量 (返回字节数)
maxMemory();
最大内存总量 …
freeMemory();
空闲内存总量 …
5.Date类与SimpleDateFormat类
Date类:表示日期和时间,提供操作日期和时间各组成部分的方法
SimpleDateFormat类:定制日期时间的格式
6. Calendar类
Copyright © 2018 Jin Hanquan. All rights reserved.
1.区别
set元素不可重复,无序
list元素可重复,有序
2.set集合的分类
(1)HashSet
方法:1.用算法算出存储索引hashCode(Object obj);;2.存入元素equals();)
效果:自动去重,散列形式
返回值:int型整数,对象的hashcode
TreeSet
(2)TreeSet
特点:对加入集合中的元素自动进行去重和排序,但是必须在重写的方法中编写排序规则
comparable<T>接口
int comparableTo();方法
if return 1;
else if return 1;
else return 0;
3.接口
4. 功能
动态存放多个对象
5. 例子
List<String> list=new ArrayList<String>();
Collections.addAll(list,"字符串1","字符串2",……);\\全部添加
Collections.add(list);\\添加
Collections.shuffle(list); \\打乱
Collections.reverse(list);\\反转
模拟栈数据结构(先进后出FILO)::
LinkedList<String> list=new LinkedList<String>();
list.push("字符串1");
list.push("字符串2");
list.pop();
list.pop();
\\输出为 字符串2 字符串1
模拟队列数据结构(先进先出FIFO):
list.add("字符串1");
list.add("字符串2");
list.removeFirst();
list.removeFirst();
\\输出为 字符串1 字符串2
遍历字符串类型的数组
for(int i=0;i<list.size();i++){
list.get(i)+" "; // List接口扩展法:get(int index)方法
for(String str:list){
str+" "; // List加强for循环遍历
二、常用类
1. Math类
常用静态方法
2. Random类
public int nextInt(int bound)
返回从0(包含)到bound(不包含)的一个“伪随机” 整数值。
public boolean nextBoolean()
返回一个“伪随机”的boolean值
3. System类
public static void arraycopy(Object src,intsrcPos,Objectdest,intdestPos,int
length)
public static void exit(int status)
public static long currentTimeMillis()
*final不能被继承,不能被实例化(private 私有化)
4. Runtime类
totalMemory();
当前内存总量 (返回字节数)
maxMemory();
最大内存总量 …
freeMemory();
空闲内存总量 …
5.Date类与SimpleDateFormat类
Date类:表示日期和时间,提供操作日期和时间各组成部分的方法
SimpleDateFormat类:定制日期时间的格式
6. Calendar类
Copyright © 2018 Jin Hanquan. All rights reserved.
相关文章推荐
- Java基础之常用类--System、Runtime、Date、Calendar、Math、Random
- Java基础 System,Runtime,Date,Calendar,Math-Random,Io流
- java--jdk api中其他对象(System,Runtime,Calendar,Math,Random,Date)
- java--jdk api中其他对象(System,Runtime,Calendar,Math,Random,Date)
- day11 常用类 System Runtime Math Random Date DateFormat SimpleDateFormat Calendar
- 黑马程序员 Java基础之System,Runtime,Date,Calendar,Math.Random对象
- 黑马程序员——JAVA基础之System,Runtime,Date,Calendar,Math
- 黑马程序员-day18其他对象System,Runtime,Date,Calendar,Math-Random
- System_Runtime_Date_Calendar_Math-Random
- 其他常用类简介(System、Runtime、Date、Calendar、Math、Random)
- Java的常用类库 Runtime System Math Random Arrays Colnealble
- 黑马程序员_JAVA- System、Runtime、Math、Date、Calendar
- 黑马程序员--------java Collections、Arrays、高级for、可变参数、静态导入、System、Runtime、Math、Date、Calendar
- java基础-API-System、Runtime、Date、Calendar、Math
- 黑马程序员_Java其他对象(System,Runtime,Date,Calendar,Marh-Random)
- Java集合框架-5.【System类】【Runtime】【Date】【Calendar】【Math & Random】
- 黑马程序员——Java基础——其他对象(System、Runtime、Date、Calendar、Math)
- 黑马程序员_基础_System、Runtime、Date、Calendar和Math-Random等常用对象的学习笔记
- System,Runtime,Date,Calendar,Math-Random类
- Java中正则表达式及其常用类Math、Calendar、Date、BigDecimal、BigInterger、System、Rondom的使用