JavaÖÐHashMapʹÓÃ×Ô¶¨ÒåKeyÀà
×Ô¶¨ÒåµÄKeyÀàÐèÒªÖØÔØequals, hashCodeº¯Êý¡£¡£
package com.albert.test;
import java.util.Vector;
import java.util.HashMap;
/**
* @author tough_guy
*
*/
//¶ÔÓÚ×Ô¶¨ÒåµÄkey£¬ ÐèÒªÖØÔØhashCodeº¯ÊýºÍequalsº¯Êý
class IPSegment
{
long ip_s;
long ip_e;
int p;
IPSegment Reset(long f1, long f2, int f3)
{
ip_s = f1;
ip_e = f2;
p = f3;
return this;
}
public boolean equals(Object so)
{
if(! (so instanceof IPSegment))
return false;
if(this.ip_s == ((IPSegment)so).ip_s && this.ip_e == ((IPSegment)so).ip_e && this.p == ((IPSegment)so).p)
return true;
else
return false;
}
public int hashCode()
{
return (int)(ip_s + ip_e + p);
}
}
public class TestString {
Vector<IPSegment> vi = new Vector<IPSegment>();
HashMap<IPSegment, Integer> hii = new HashMap<IPSegment, Integer>();
HashMap<String, String> hss = new HashMap<String, String>();
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TestString ts = new TestString();
ts.vi.add(new IPSegment().Reset(1, 2, 3));
ts.vi.add(new IPSegment().Reset(2, 2, 4));
ts.vi.add(new IPSegment().Reset(3, 2, 5));
ts.vi.add(new IPSegment().Reset(4, 2, 6));
System.out.println(ts.vi.size());
System.out.println(ts.vi.get(2).ip_s + "\t" + ts.vi.get(2).ip_e + "\t" + ts.vi.get(2).p);
ts.hii.put(new IPSegment().Reset(2,2,3), 4);
ts.hii.put(new IPSegment().Reset(2,3,3), 7);
ts.hii.put(new IPSegment().Reset(3,2,3), 9);
System.out.println(ts.hii.size());
System.out.println(ts.hii.toString());
System.out.println((Integer)ts.hii.get(new IPSegment().Reset(2,3,3)));
System.out.println((Integer)ts.hii.get(new IPSegment().Reset(3,2,3)));
ts.hss.put("1", "hello");
System.out.println((String)ts.hss.get("1"));
}
}
Ïà¹ØÎĵµ£º
ÔËÐÐ×Ô¼ºÅäÖõÄwebÓ¦Óã¬ÍùÍùÖ»ÄÜ¿´¼ûweblogic±àÒëÖ®ºóµÄclassÎļþ¡£¶ø¿´²»¼û±àÒëÇ°µÄjavaµÄÎļþ¡£ÎªÁ˵÷ÊÔ·½±ã£¬ÎÒÃÇÓÐʱºòÊÇÏë¿´±àÒëÇ°µÄjavaÎļþ¡£
ÔÚweblogic.xmlÖмÓÈë
<jsp-descriptor>
<jsp-param>
<param-name>keepgenerated</param-name>
<param-value>true</par ......
package thread.lock;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
* @file_name ReadAndWriteLockDemo.java
* @description ¶ÁÐ ......
javeÔõôѧϰ×î¿ì
2008-11-08 06:57
ÓûËÙÔò²»´ï£¬Ñ§Ï°JAVAûÓГ¿ÉÒÔÀ”ÕâÖ̶ֳȡ£·á¸»¶à²Ê£¬Ñ§Ï°Ò»ÄêµÄʱ¼äÒ²²»Ò»¶¨ÄÜѧÍê»ù´¡£¬ÎÒÔø¾Ò²Ïë¹ýÕâ¸öÎÊÌ⣬µ«ºóÀ´¿´ÁËһƪÎÄÕ£¬±ã³¹È»ÐÑÎò¡£ÏÂÃæÕâƪÎÄÕ£¨²»ÒªÏÓ³¤£¬¿´Íê¾ÍÓÐÊÕÒ棬»¹ÓдËÎÊÌâ²»Òª¹Ø±Õ»òÊÇͶƱ£¬»Ø´ð¶¼ÊÇÐÁ¿àµØ£¬²»Òª´ò»ý¼«ÐÔ£¬²»¹»ºÃÒ²½«¾ÍЩ°É ......
³õѧÕ߸üÊʺÏʹÓÃÎı¾±à¼Èí¼þÀ´Ñ§Ï°Java£¬¶ÔJavaÓÐÒ»¶¨ÈÏʶºóÍƼöʹÓÃEclipse£¬¶ÔÄÇЩҪÇ󿪷¢Ð§ÂʵijÌÐòÔ±µ±È»Ê×Ñ¡¾ÍÊÇJBuilder¡£
¶ÔÓÚÎı¾±à¼Èí¼þÎÒÍƼöEditPlus£¬EditPlusÊǺܶà³ÌÐòÔ±·Ç³£ÊìϤµÄ±à¼¹¤¾ß£¬ËüÒÔÕ¼ÓÃϵͳ×Ê
ԴС¡¢²Ù×÷¼ò±ãÁé»î¡¢Ö§³ÖÎļþÀàÐͷḻ ......
ת×Ô£ºhttp://blog.163.com/gordonkkk/blog/static/63425684200962795039630/
´ÓCSDNÉÏ¿´µ½Ò»ÆªÅúÆÀJavaÓïÑÔÖî¶àÎÊÌâµÄ·ÒëÎÄÕ£¬ÔÎÄ×÷ÕßÊÇMario Fusco¡£ËûÖ¸³öÁËJavaÓïÑÔÂäºóÓÚʱ´ú£¬»ýÖØÄÑ·µµÄ10¸öÎÊÌâ¡£¿´¹ýÖ®ºóÒýÆðÁËÎÒµÄһЩÁªÏë¡£ÏÂÃæÁгöËûËù˵µÄ10´óÎÊÌâ¡£½Û»ÆÉ«×ÖÌåÊÇÎÒÒ»µãµã²»³ÉÊìµÄ˼¿¼¡£
1¡¢È±ÉÙ±Õ°ü£¨clos ......