• Java并发编程从入门到精通


    Hashtable;

     1 /**
     2  * Hashtable的简单用法
     3  */
     4 package thread03;
     5 
     6 import java.util.Hashtable;
     7 
     8 public class HashtableTest01
     9 {
    10     public static void main(String[] args)
    11     {
    12         Hashtable<String,Integer> ht = new Hashtable<String,Integer>();
    13         ht.put("one", 1);
    14         ht.put("two", 2);
    15         ht.put("three", 3);
    16         
    17         Integer num = ht.get("two");
    18         if(null != num)
    19         {
    20             System.out.println("two = " + num);
    21         }
    22     }
    23 }
    Hashtable的简单用法

    ConcurrentHashMap;

     1 /**
     2  * ConcurrentHashMap的简单用法
     3  */
     4 package thread03;
     5 
     6 import java.util.concurrent.ConcurrentHashMap;
     7 
     8 public class ConcurrentHashMapTest01
     9 {
    10     public static void main(String[] args)
    11     {
    12         ConcurrentHashMap<String,Integer> ch = new ConcurrentHashMap<String,Integer>();
    13         ch.put("one", 1);
    14         ch.put("two", 2);
    15         ch.put("three", 3);
    16         
    17         System.out.println(ch.get("two"));
    18         
    19         if(ch.containsKey("one") && ch.get("one").equals(1))
    20         {
    21             ch.remove("one");
    22         }
    23     }
    24 }
    ConcurrentHashMap的简单用法

    CopyOnWriteArrayList;

     1 /**
     2  * CopyOnWriteArrayList的简单用法
     3  */
     4 package thread03;
     5 
     6 import java.util.Iterator;
     7 import java.util.concurrent.CopyOnWriteArrayList;
     8 
     9 public class CopyOnWriteArrayListTest01
    10 {
    11     public static void main(String[] args)
    12     {
    13         CopyOnWriteArrayList<String> cwal = new CopyOnWriteArrayList<String>();
    14         cwal.add("one");
    15         cwal.add("three");
    16         cwal.add(1, "two");
    17         
    18         System.out.println(cwal.get(1));
    19         
    20         if(cwal.contains("three"))
    21         {
    22             Iterator<String> it = cwal.iterator();
    23             while(it.hasNext())
    24             {
    25                 System.out.println(it.next());
    26             }
    27         }
    28     }
    29 }
    CopyOnWriteArrayList的简单用法

    CopyOnWriteArraySet;

     1 /**
     2  * CopyOnWriteArraySet的简单用法
     3  */
     4 package thread03;
     5 
     6 import java.util.Iterator;
     7 import java.util.concurrent.CopyOnWriteArraySet;
     8 
     9 public class CopyOnWriteArraySetTest01
    10 {
    11     public static void main(String[] args)
    12     {
    13         CopyOnWriteArraySet<String> cwas = new CopyOnWriteArraySet<String>();
    14         cwas.add("one");
    15         cwas.add("two");
    16         cwas.add("three");
    17         
    18         if(cwas.contains("three"))
    19         {
    20             Iterator<String> it = cwas.iterator();
    21             while(it.hasNext())
    22             {
    23                 System.out.println(it.next());
    24             }
    25         }
    26     }
    27 }
    CopyOnWriteArraySet的简单用法

    Vector;

     1 /**
     2  * Vector的简单用法
     3  */
     4 package thread03;
     5 
     6 import java.util.Iterator;
     7 import java.util.Vector;
     8 
     9 public class VectorTest01
    10 {
    11     public static void main(String[] args)
    12     {
    13         Vector<String> vector = new Vector<String>();
    14         vector.addElement("one");
    15         vector.addElement("two");
    16         vector.addElement("three");
    17         vector.removeElement("two");
    18         
    19         if(vector.contains("three"))
    20         {
    21             Iterator<String> it = vector.iterator();
    22             while(it.hasNext())
    23             {
    24                 System.out.println(it.next());
    25             }
    26         }
    27     }
    28 }
    Vector的简单用法

    StringBuffer;

  • 相关阅读:
    IK 用java 代码实现分词
    杭电2017
    线性表学习
    一个比较有意思的C语言问题
    杭电1020
    python注释
    Java API —— 递归
    Java API —— File类
    Java API —— 异常
    Map集合案例
  • 原文地址:https://www.cnblogs.com/kehuaihan/p/8460209.html
Copyright © 2020-2023  润新知