java例程练习(字符流)

摘要: import java.io.*;public class TestFileReader { public static void main(String[] args) { FileReader fr = null; int c = 0; try { fr = new FileReader("C:/java/Test.java"); while((c = fr.read()) != -1) { System.out.print((char)c); } fr.close(); } catch (FileNotFoundException e) { Sys... 阅读全文
posted @ 2012-05-01 22:18 Yours风之恋 阅读(139) 评论(0) 推荐(0)

Java例程练习(字节流)

摘要: import java.io.*;public class Test { public static void main(String[] args) { int b = 0; FileInputStream in = null; try { in = new FileInputStream("C:/java/Test.java"); } catch (FileNotFoundException e) { System.out.println("找不到指定文件"); System.exit(-1); } try { long num = 0... 阅读全文
posted @ 2012-05-01 21:37 Yours风之恋 阅读(155) 评论(0) 推荐(0)

java例程练习(泛型和自动打包、解包)

摘要: //TestArsgWords.javaimport java.util.*;public class TestArgsWords { public static void main(String[] args) { Map m = new HashMap(); for(int i = 0; i c = new ArrayList(); c.add("aaa"); c.add("bbb"); c.add("ccc"); for(int i = 0; i c2 = new HashSet (); c2.add("aaa&quo 阅读全文
posted @ 2012-05-01 15:06 Yours风之恋 阅读(221) 评论(0) 推荐(0)

java例程练习(用HashMap记录控制台输入)

摘要: import java.util.*;public class TestArgsWords { public static void main(String[] args) { Map m = new HashMap(); for(int i = 0; i < args.length; i++) { int freq = ((Integer) m.get(args[i]) == null ? 0 : (Integer) m.get(args[i])); m.put(args[i], (freq == 0 ? 1 : freq + 1)); } System.o... 阅读全文
posted @ 2012-05-01 14:41 Yours风之恋 阅读(214) 评论(0) 推荐(0)

java例程练习(Map接口及自动打包、解包)

摘要: import java.util.*;public class Test { public static void main(String[] args) { Map m1 = new HashMap(); Map m2 = new HashMap(); m1.put("one", 1); //m1.put("one",new Integer(1)); m1.put("two", 2); //m1.put("two",new Integer(2)); m1.put("three", 3); // 阅读全文
posted @ 2012-05-01 14:21 Yours风之恋 阅读(213) 评论(0) 推荐(0)

java例程练习(Comparable接口)

摘要: import java.lang.Comparable;import java.util.List;import java.util.LinkedList;import java.util.Collections;public class TestCompareTo { public static void main(String[] args) { List l1 = new LinkedList(); l1.add(new Name("Karl", "M")); l1.add(new Name("Stever", "Le 阅读全文
posted @ 2012-05-01 13:40 Yours风之恋 阅读(162) 评论(0) 推荐(0)

java例程练习(List常用算法)

摘要: import java.util.*;public class TestCollection { public static void main(String[] args) { List l1 = new LinkedList(); for(int i = 0; i list1 = new LinkedList(); List list2 = new LinkedList(); for(int i = 0; i <= 9; i++) { list1.add("a" + i); } System.out.println(list1); Collections.shuf 阅读全文
posted @ 2012-05-01 13:11 Yours风之恋 阅读(281) 评论(0) 推荐(0)

java例程练习(增强的for循环)

摘要: import java.util.ArrayList;import java.util.Collection;public class Test { public static void main(String[] args) { int [] arr = {1, 2, 3, 4, 5}; for(int i : arr) { System.out.print(i + " "); } System.out.println(); Collection c = new ArrayList(); c.add(new String("AAA")); c.add( 阅读全文
posted @ 2012-05-01 10:36 Yours风之恋 阅读(151) 评论(0) 推荐(0)

java例程练习(Iterator)

摘要: import java.util.Collection;import java.util.HashSet;import java.util.Iterator;public class Test { public static void main(String[] args) { Collection c = new HashSet(); c.add(new Name("f1", "l1")); c.add(new Name("f2", "l2")); c.add(new Name("f3", & 阅读全文
posted @ 2012-05-01 10:27 Yours风之恋 阅读(196) 评论(0) 推荐(0)