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风之恋 阅读(204) 评论(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风之恋 阅读(199) 评论(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风之恋 阅读(151) 评论(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风之恋 阅读(267) 评论(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风之恋 阅读(140) 评论(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风之恋 阅读(186) 评论(0) 推荐(0) 编辑

java例程练习(容器类简单练习)

摘要: import java.util.ArrayList;import java.util.Collection;public class Test { public static void main(String[] args) { Collection c = new ArrayList(); c.add("hello"); c.add(new Name("f1", "l1")); c.add(new Integer(100)); System.out.println(c.size()); System.out.println(c); 阅读全文
posted @ 2012-04-30 20:29 Yours风之恋 阅读(151) 评论(0) 推荐(0) 编辑

java例程练习(枚举Enum类)

摘要: public class Test { public enum MyColor {red, green, blue}; public static void main(String[] args) { MyColor m = MyColor.red; switch(m) { case red: System.out.println("red"); break; case green: System.out.println("green"); break; case blue: System.out.println("blue"); b 阅读全文
posted @ 2012-04-30 20:02 Yours风之恋 阅读(285) 评论(0) 推荐(0) 编辑

java例程练习(引用类型数据的排序和查找)[外篇]

摘要: public class TestSort { public static void main(String[] args) { Date[] days = new Date[5]; //定义5个Date days[0] = new Date(2006, 8, 6); days[1] = new Date(2007, 4, 6); days[2] = new Date(2008, 4, 9); days[3] = new Date(2004, 4, 6); days[4] = new Date(2009, 4, 5); //要找的Date Date d = new Da... 阅读全文
posted @ 2012-04-30 10:39 Yours风之恋 阅读(335) 评论(0) 推荐(0) 编辑

java例程练习(数组复制与arraycopy)

摘要: //数组拷贝public class Test { public static void main(String[] args) { String[] s = {"Microsoft", "IBM", "Sun", "Oracle", "Apple"}; String[] sCopy = new String[6]; System.arraycopy(s, 0, sCopy, 0, s.length); for(int i = 0; i < s.length; i++) { System. 阅读全文
posted @ 2012-04-29 23:23 Yours风之恋 阅读(216) 评论(0) 推荐(0) 编辑