zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    Appium Android 元素定位方法 原生+H5
    Eclipse下Python的MySQLdb的安装以及相关问题
    Python模块包中__init__.py文件的作用
    如何调用另一个python文件中的代码
    Python单元测试框架unittest使用方法讲解
    python利用unittest进行测试用例执行的几种方式
    python随机生成手机号码
    eclipse 安装python后pydev不出现
    Appium 如何模拟返回按键
    python分布式进程
  • 原文地址:https://www.cnblogs.com/kehuaihan/p/8460209.html
Copyright © 2011-2022 走看看