java集合测试类等

package demo.mytest;

import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Queue;
import java.util.Set;
import java.util.TreeMap;
import java.util.Map.Entry;

/**
* 在很多情况下,主线程生成并起动了子线程,如果子线程里要进行大量的耗时的运算,
* 主线程往往将于子线程之前结束,但是如果主线程处理完其他的事务后,需要用到子线程的处理结果,
* 也就是主线程需要等待子线程执行完成之后再结束,这个时候就要用到join()方法了。
* @author Administrator
*
*/
public class TestDemo {
public static void main(String[] args) {
// String threadName = Thread.currentThread().getName();
// System.out.println(threadName + " start.");
// BThread bt = new BThread();
// AThread at = new AThread(bt);
// try {
// bt.start();
// Thread.sleep(2000);
// at.start();
// at.join();
// } catch (Exception e) {
// System.out.println("Exception from main");
// }
// System.out.println(threadName + " end!");

// Queue<String> queue = new LinkedList<String>();
// queue.offer("Hello");
// queue.offer("World!");
// queue.offer("好吧!");
// queue.offer("你好!");
// System.out.println(queue.size());
// String str;
// while((str=queue.poll())!=null){
// System.out.print(str);
// }
// System.out.println();
// System.out.println(queue.size());

// System.out.println("*************************LinkedHashMap*************");
// Map<Integer,String> map = new LinkedHashMap<Integer,String>();
// map.put(6, "apple");
// map.put(7, "banana");
// map.put(2,"pear");
//
// for (Iterator it = map.keySet().iterator();it.hasNext();)
// {
// Object key = it.next();
// System.out.println( key+"="+ map.get(key));
// }
// System.out.println("*************************HashMap*************");
// Map<Integer,String> map1 = new HashMap<Integer,String>();
// map1.put(6, "apple");
// map1.put(7, "banana");
// map1.put(2,"pear");
//
// for (Iterator it = map1.keySet().iterator();it.hasNext();)
// {
// Object key = it.next();
// System.out.println( key+"="+ map1.get(key));
// }

//HashMap
// System.out.println("------HashMap无序输出------");
// HashMap hsMap=new HashMap();
// hsMap.put("3", "Value3");
// hsMap.put("1", "Value1");
// hsMap.put("2", "Value2");
// hsMap.put("b", "ValueB");
// hsMap.put("a", "ValueA");
// Iterator it = hsMap.entrySet().iterator();
// while (it.hasNext()) {
// Map.Entry e = (Map.Entry) it.next();
// System.out.println("Key: " + e.getKey() + "--Value: "
// + e.getValue());
// }
//
// //TreeMap
// System.out.println("------TreeMap按Key排序输出------");
// TreeMap teMap=new TreeMap();
// teMap.put("3", "Value3");
// teMap.put("1", "Value1");
// teMap.put("2", "Value2");
// teMap.put("b", "ValueB");
// teMap.put("a", "ValueA");
// Iterator tit = teMap.entrySet().iterator();
// while (tit.hasNext()) {
// Map.Entry e = (Map.Entry) tit.next();
// System.out.println("Key: " + e.getKey() + "--Value: "
// + e.getValue());
// }
//
// //LinkedHashMap
// System.out.println("--LinkedHashMap根据输入的顺序输出--");
// LinkedHashMap lhsMap=new LinkedHashMap();
// lhsMap.put("3", "Value3");
// lhsMap.put("1", "Value1");
// lhsMap.put("2", "Value2");
// lhsMap.put("b", "ValueB");
// lhsMap.put("a", "ValueA");
// Iterator lit = lhsMap.entrySet().iterator();
// while (lit.hasNext()) {
// Map.Entry e = (Map.Entry) lit.next();
// System.out.println("Key: " + e.getKey() + "--Value: "
// + e.getValue());
// }


// List<String> listWithDup = new ArrayList<String>();
// listWithDup.add("1");
// listWithDup.add("2");
// listWithDup.add("3");
// listWithDup.add("1");
//
// List<String> listWithoutDup = new ArrayList<String>(new HashSet<String>(listWithDup));
// List<String> lists=new ArrayList<String>(new HashSet<String>(listWithDup));
// System.out.println("list with dup:"+ listWithDup);
// System.out.println("list without dup:"+ listWithoutDup);
// List list=new ArrayList();
// list.add("1");
// list.add("2");
// list.add("a");
// list.add("b");
// list.add("2");
// list.add("b");
// List list1= removeDuplicate(list);
// for(int i=0;i<list1.size();i++){
// System.out.println(list1.get(i));
// }

//弱引用.
// SoftReference<String> sr=new SoftReference<String>(new String("hello"));
// System.out.println("sr:"+sr.get());
// System.gc();
// System.out.println("sr2:"+sr.get());

//软引用
// WeakReference<String> wr=new WeakReference<String>(new String("hello"));
// System.out.println("wr:"+wr.get());
// System.gc();
// System.out.println("wr2:"+wr.get());

//Properties pps = System.getProperties();
//pps.list(System.out);
//String s="412723199902072119";//41**********2119
String s="130503670401001";
String s1=s.substring(2, s.length()-4);
StringBuffer sb=new StringBuffer(s.substring(0, 2));
for(int i=2;i<s.length()-4;i++){
sb.append("*");
}
sb.append(s.substring(s.length()-4));
System.out.println("s:"+s+",s1:"+s1+",sb:"+sb+",s:"+s.length());
// String s1=s.substring(2,s.length()-4);
// String s2=s.replace(s1,"************");
// System.out.println("s2:"+s2+",length:"+s2.length());
}
private static List removeDuplicate(List list) {
Set set = new HashSet();
List newList = new ArrayList();

for(Iterator iter = list.iterator();iter.hasNext();) {
Object element = iter.next();
if(set.add(element)) {
newList.add(element);
}
}
return newList;

}
}

posted @ 2015-12-31 09:52  java高级技术汇  阅读(233)  评论(0)    收藏  举报