Example usage for java.util HashMap HashMap

List of usage examples for java.util HashMap HashMap

Introduction

In this page you can find the example usage for java.util HashMap HashMap.

Prototype

public HashMap() 

Source Link

Document

Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).

Usage

From source file:license.mac.MacTest.java

public static void main(String[] args) throws Exception {
    Map<Integer, String> infoMap = new HashMap<Integer, String>();
    infoMap.put(1, "");
    infoMap.put(2, "");
    infoMap.put(2, "");
    infoMap.put(2, "");
    infoMap.put(12, "eth0");

    MacTest mac = new MacTest();

    System.out.println();/* w  w  w. j  av a 2  s .  co m*/
    System.out.println();
    System.out.println("************?mac?*********");
    System.out.println();
    System.out.println();
    InetAddress ia = InetAddress.getLocalHost();//?IP
    System.out.println("IP .........: " + ia.getHostAddress());
    System.out.println("MAC .........: " + getMACAddress(ia));

    System.out.println();
    System.out.println();
    mac.checkMac();
}

From source file:Main.java

public static void main(String args[]) {
    MyObject c1 = new MyObject(1, "one");
    MyObject c2 = new MyObject(2, "two");
    MyObject c3 = new MyObject(3, "three");

    MyObject c4 = new MyObject(1, "one");
    MyObject c5 = new MyObject(2, "two");
    MyObject c6 = new MyObject(3, "three");

    Map<Integer, MyObject> map = new HashMap<Integer, MyObject>();
    map.put(c1.getId(), c1);/*w w w  .ja  va2 s.c o m*/
    map.put(c2.getId(), c2);
    map.put(c3.getId(), c3);
    map.put(c4.getId(), c4);
    map.put(c5.getId(), c5);
    map.put(c6.getId(), c6);

    System.out.println(map);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    XMLInputFactory xif = XMLInputFactory.newFactory();
    XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("data.xml"));
    xsr.nextTag(); // advance to Employees tag
    xsr.nextTag(); // advance to first Employer element
    Map<String, String> map = new HashMap<String, String>();
    while (xsr.getLocalName().equals("Employee")) {
        map.put(xsr.getAttributeValue("", "id"), xsr.getElementText());
        xsr.nextTag(); // advance to next Employer element
    }// w  ww . j a  v a2  s . co m
}

From source file:RandomGenTest.java

public static void main(String[] args) {
    RandomDataGenerator rand = new RandomDataGenerator();

    Map<Object, Integer> map = new HashMap();
    for (int i = 0; i < 101; i++)
        map.put(i, 0);/*from  w ww  .  ja v  a2  s.  co m*/

    Map<Object, Integer> user = new HashMap();
    for (int i = 0; i < 100; i++) {
        int age = rand.nextInt(0, 100);
        /*int age = (int) rand.nextGaussian(50, 10D);
        if ((age > 100) || (age < 0)) {
           age = rand.nextInt(0, 100);
        }*/
        user.put(i, age);
    }

    for (int i = 0; i < 100000; i++) {
        //int age = rand.nextInt(0, 100);
        /*int age = (int) rand.nextGaussian(50, 10D);
        if ((age > 100) || (age < 0)) {
           age = rand.nextInt(0, 100);
        }*/

        //Seq
        //map.put(user.get(i%100), map.get(user.get(i%100))+1);

        //Rand
        int j = rand.nextInt(0, 99);
        map.put(user.get(j), map.get(user.get(j)) + 1);
    }

    display(map);
}

From source file:Main.java

public static void main(String[] args) {
    Collection<String> c = Collections.synchronizedCollection(new ArrayList<String>());
    List<String> list = Collections.synchronizedList(new ArrayList<String>());
    Set<String> s = Collections.synchronizedSet(new HashSet<String>());
    Map<String, String> m = Collections.synchronizedMap(new HashMap<String, String>());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    List stuff = Arrays.asList(new String[] { "a", "b" });

    List list = new ArrayList(stuff);
    List list2 = new LinkedList(list);

    Set set = new HashSet(stuff);
    Set set2 = new TreeSet(set);

    Map map = new HashMap();
    Map map2 = new TreeMap(map);
}

From source file:com.ykun.commons.utils.http.HttpClientTest.java

public static void main(String[] args) throws Exception {

    System.out.println(HttpClientUtils.get("http://www.weather.com.cn/data/sk/101010100.html"));

    Map<String, String> params = new HashMap<String, String>();
    params.put("gameID", "1000001");
    params.put("accountID", "helloworld2");
    System.out.println(HttpClientUtils.post("http://115.159.156.171/home/main", params));

    System.out.println(HttpClientUtils.execute(Request.Post("http://115.159.156.171/home/main")
            .bodyForm(Form.form().add("gameID", "1000001").add("accountID", "helloworld2").build())));

}

From source file:Main.java

public static void main(String[] args) {
    ReferenceQueue referenceQueue = new ReferenceQueue();
    Object object = new Object() {
        public String toString() {
            return "Referenced Object";
        }// w w w .  j av  a  2 s .  c o m
    };
    Object data = new Object() {
        public String toString() {
            return "Data";
        }
    };

    HashMap map = new HashMap();
    Reference reference = new SoftReference(object, referenceQueue);

    map.put(reference, data);

    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());

    System.gc();
    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());

    object = null;
    data = null;

    System.gc();
    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());
}

From source file:Main.java

public static void main(String[] args) {
    ReferenceQueue referenceQueue = new ReferenceQueue();
    Object object = new Object() {
        public String toString() {
            return "Referenced Object";
        }/*from  ww w  . ja  va  2  s .  c  o m*/
    };

    Object data = new Object() {
        public String toString() {
            return "Data";
        }
    };

    HashMap map = new HashMap();
    Reference reference = null;
    System.out.println("Testing PhantomReference.");
    reference = new PhantomReference(object, referenceQueue);

    map.put(reference, data);

    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());

    System.gc();
    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());

    object = null;
    data = null;

    System.gc();
    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());
}

From source file:common.ReverseWordsCount.java

public static void main(String[] args) throws IOException {
    List<String> readLines = FileUtils.readLines(new File("G:\\\\LTNMT\\LTNMT\\sougou\\sougou2500.txt"));
    Map<String, Integer> words = new HashMap<>();

    for (String line : readLines) {
        String[] split = line.split(" ");
        for (String wprd : split) {
            Integer get = words.get(wprd);
            if (get == null) {
                words.put(wprd, 1);//w  w  w .  j a v a2s  .  c  o m
            } else {
                words.put(wprd, get + 1);
            }
        }
    }
    Set<Map.Entry<String, Integer>> entrySet = words.entrySet();
    List<Map.Entry<String, Integer>> reverseLists = new ArrayList<>(entrySet);
    Collections.sort(reverseLists, new Comparator<Map.Entry<String, Integer>>() {
        @Override
        public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
            return o2.getValue().compareTo(o1.getValue());
        }
    });
    PrintStream ps = new PrintStream("c:/reverseWords.txt");
    for (Map.Entry<String, Integer> teEntry : reverseLists) {
        ps.println(teEntry.getKey() + " " + teEntry.getValue());
    }
    ps.close();
}