• 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;

  • 相关阅读:
    第三方接口开发规范
    项目经理、技术经理、team leader
    ibatis #和$符号的区别,传入字符串而不加引号
    WindowManager.LayoutParams详解
    AIDL 编译报can be an out parameter, so you must declare it as in, out or inout原因探究
    map里的keyset()和entryset()方法.
    android 使用代码实现 RelativeLayout布局
    Android中的Selector
    intentfilter 之 data 「scheme, host, port, mimeType, path, pathPrefix, pathPattern」
    找信息的方法
  • 原文地址:https://www.cnblogs.com/kehuaihan/p/8460209.html
Copyright © 2020-2023  润新知