摘要:
//TestArsgWords.java
import java.util.*;
public class TestArgsWords { public static void main(String[] args) { Map<String, Integer> m = new HashMap<String, Integer>(); for(int i = 0; i < args.length; i++) { if(!m.containsKey(args[i])) { m.put(args[i], 1); } else { int fr... 阅读全文
摘要:
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)); }
... 阅读全文
摘要:
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); / 阅读全文
摘要:
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", &quo 阅读全文
摘要:
import java.util.*; public class TestCollection { public static void main(String[] args) { List<String> l1 = new LinkedList<String>(); for(int i = 0; i <= 5; i++) { l1.add("a" + i); } System.out.println(l1); l1.add(3, "a100"); System.out.println(l1); l1.set(6, &quo 阅读全文
摘要:
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<String> c = new ArrayList<String>(); c.add(new St 阅读全文
摘要:
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator; public class Test { public static void main(String[] args) { Collection<Name> c = new HashSet<Name>(); c.add(new Name("f1", "l1")); c.add(new Name("f2", "l2")); c.add 阅读全文