集合框架和包装类

集合框架和包装类
Object类包装类
Object类是所有类的直接父类或去间接父类
所有类都可以声明Object引用
引用
getClass()方法 返回一个对象的实际类型(对象相等)
equals()方法 两个对象的内容是否相等 重写方法可以时对象相等
toString()方法 返回一个对象字符串表示形式
可以重写Object子类的方法
包装类
包装类与基本类型转换
int转换为Integer
int i=10;
Integer I=new Integer(i);//这样更好,会利用缓存
Integer I = Integer.valueOf(i);
Integer转换为int
Integer i=new Integer(10);
int i=I.intValue();
包装类和string类型转换
string转换为Integer
Strig s=“12”;
Integer I=new Integer(s);
Integer I = Integer.valueOf(s); //更好
I
nteger转换为string

Integer I=new Integer(23);
基本类型和string类型转换
string转换为int
String s=“20”;
int i=Integer.parseInt(s);
int转换为String
int i=20;
String s1=String.valueOf(i);
String s2=""+i;
什么是集合
如果并不知道程序运行时会需要多少对象,或者需要
更复杂方式存储对象——可以使用Java集合框架
1、接口
Collection:List -ArrayList
List-LinkedList
Set-HashSet
Set-Treeset
Map HashMap
TreeMap
提供了对集合进行排序、遍历等多种算法
ArrayList与LinkedList区别
遍历元素和随机访问元素的效率比较高
LinkedList采用链表存储方式。插入、删除元素时效率比较高
为什么使用框架
集合长度可以自由扩充
集合里边任何类型都可以放
Java集合框架提供了一套性能优良、使用方便的接口和类,它们位于java.util包中