1.test1.flush();//刷新缓冲区
2.close();
3.
//缓冲区吓到硬盘上的三个方法
1.test1.flush();//刷新缓冲区
2.close();
3.
//缓冲区吓到硬盘上的三个方法
最后一题
public static void test() {
FileReader reader = null;
try {
reader = new FileReader("demo\\calcCharNum.txt");
StringBuffer str = new StringBuffer();
char[] text = new char[1024];
int length = -1;
int countOfa = 0;
int countOfA = 0;
while ((length = reader.read(text)) > -1) {
str.append(text, 0, length);
}
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c == 'a') {
countOfa++;
} else if (c == 'A') {
countOfA++;
}
}
System.out.println("a出现的次数:" + countOfa + " A出现的次数:" + countOfA);
} catch (IOException e) {
e.printStackTrace();
}
}
Interator
hashset不重复且无序
集合频繁的插入和删除数据 要用linklist
HashSet<Integer> new_al=new HashSet();
new_al.addAll(al);
MAP(储存键值对)
HashMap
TreeMap
Hashtable
Collection()
1、TreeMap 和 HashMap中的属性差不多
public static void printFiles(String path,int level) {
File f = new File(path);
String sub = "";
for (int i =0;i<level-1;i++){
sub +=" ";
}
if(f.isDirectory()) {
System.err.println(sub+"文件夹: "+f.getName());
String[] files = f.list();
for(String filename : files) {
printFiles(path+"/"+filename,level +1);
}
}else {
System.out.println(sub+"文件: "+f.getName());
}
}
List al=new ArrayList();
al.add("123");
定义:
public class MyArrayList<T>
{
}
private T[] dataArray=( T[] ) new object[100];
声明 dataArray为 强制 object好用之处
T类型的数组 转换为T类型
HashMap: (key,value),
key不能相同,如果key相同,则后面覆盖前面。
遍历:key是一个序列,用map.KeySet()获得其中一个
HashMap map=new HashMap();
for( Object key: map.KeySet())
{
System.out.println( map.get(key) );
}
value也是一个序列,map.values()获得其中一个
集合可以存储自定义数据类型,
泛型到自己定义的类,
ArrayList <Student>= new ArrayList<Studeng> s
TreeSet 与 HashSet的区别:
Hash set 之内没有重复数据,且无序,无法通过index获取某个元素。
我的笔记
set是无序的是hash存储,是不重复的,因为hash是不能重复的,没有索引的概念,不重复
可以方便的插入数据和删除数据基于数据结构(速度快),当频繁的中间插入数据,使用LinkList
//和ArrayList区别,Vector的线程是安全的,ArrayList的线程是不安全的
//所有ArrayList的速度会比Vector快多线程的时候