- 浏览: 28435 次
最新评论
文章列表
//迭代器Iterator接口
//判断是否有内容,有的话,就取出
//只需要用Collection接口的iterator(),就能实例化Iterator接口
public static void main(String[] args) {
List<Integer> arrayList = new ArrayList<Integer>();
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);
Iterator<Integer> iterator = ...
public static void main(String[] args) {
//Set接口,不能存放重复的元素
//实现类,HashSet(无序存放)
//实现类,TreeSet(有序存放)
Set<String> treeSet = new TreeSet<String>();
treeSet.add("1234qwer");
treeSet.add("看看");
treeSet.add("qw");
treeSet.add("abc& ...
public static void main(String[] args) {
LinkedList<String> linkedList = new LinkedList<String>();
linkedList.add("1");
linkedList.add("2341");
linkedList.add("以为");
System.out.println(linkedList);
linkedList.addFirst("first&q ...
public static void main(String[] args) {
List<Character> arrayList = new ArrayList<Character>();
arrayList.add('a');
arrayList.add('b');
arrayList.add('c');
arrayList.add('d');// 添加元素
// 遍历输出
for (int i = 0; i < arrayList.size(); i++) {
System.out.print(arr ...
//对象序列化
//所谓对象序列化,即把一个对象,变为二进制
//对象所在的类,须实现Serializable接口
public static void main(String[] args) throws Exception {
ObjectOutputStream objectOutput=
new ObjectOutputStream(new FileOutputStream(new File("d:"+File.separator+"t2.txt")));
objectOutput.writeObject(ne ...
// 解压缩文件
public static void main(String[] args) throws Exception {
// 首先找到,要解压缩的文件
File file = new File("d:" + File.separator + "2.zip");
// 每一个压缩文件,都可以用ZipFile表示
ZipFile zipFile = new ZipFile(file);
// 读取zip格式文件,要用到ZipInputStream类
ZipInputStream zipInput ...
// 压缩文件夹
//先用输入流读取文件,之后再用压缩流输出文件
public static void main(String[] args) throws Exception {
File file = new File("d:" + File.separator + "myDir");// 源文件
File zipFile = new File("d:" + File.separator + "2.zip");// 被压缩文件的路径
InputStream inputStream ...
//压缩文件
//先用输入流读取文件,之后再用压缩流输出文件
public static void main(String[] args) throws Exception {
File file = new File("d:" + File.separator + "demo.pdf");// 源文件
File zipFile = new File("d:" + file.separator + "1.zip");// 被压缩文件的路径
InputStream fileReader ...
package io;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//一个处理输入数据的类(用正则表达式验证),只能输入整数
class MyInput {
private BufferedReader reader = null;
public MyInput() {
reader = new BufferedReader(new InputStreamReader(System.in));
}
pu ...
// 输出重定向
// 让System.out.println()的内容,输出到硬盘文件上
public static void main(String[] args) throws Exception {
System.setOut(new PrintStream(new FileOutputStream(new File("d:" + File.separator + "T1.txt"))));
System.out.println("just a test");
System.out.printl ...
//打印流
public static void main(String[] args) throws Exception {
//装饰设计模式,重新包装FileOutputStream,让它的输出更容易
PrintStream printStream =
new PrintStream(new FileOutputStream(new File("c:" + File.separator + "T1.txt")));
//以下内容,直接输出到文件
printStream.print("so ...
//字符流,Reader和Writer
//字符输出流Writer
//向文件写入一个字符串
public static void main(String[] args) throws Exception {
String path="d:"+File.separator+"T2.txt";//找到文件路径
File file = new File(path);
// Writer fileWriter = new FileWriter(file);
Writer fileWriter = new FileW ...
//字节流,向文件写入字符串
public static void main(String[] args) throws Exception {
//输出到哪里
File file=new File("d:"+File.separator+"test.txt");
OutputStream outputStream = new FileOutputStream(file);
String str="1234qwer";//写入的字符串
byte[] bytes = str.getBy ...
public static void main(String[] args) {
String string = "0123456789";
//Pattern.compile("[0-9]+")验证的正则表达式
// .matcher(string),返回Matcher对象
// .matches(),执行验证
if (Pattern.compile("[0-9]+").matcher(string).matches()) {
System.out.println("都是数字 ...
package common_class;
import java.util.Arrays;
//比较两个对象,成绩最优的排名最前
//实现Compareable接口
class Student implements Comparable<Student> {
private String name;
private int score;
@Override
public String toString() {
return this.name + ", " + this.score;
}
public ...