JavaDay09--Notes(集合的接口与功能+常用类Math,Random,System,Runtime,Calendar)

一、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 ,int srcPos ,Object dest ,int destPos ,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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值