raojl 发表于 2013-2-4 19:49:58

散列过滤

1.在一些字符串数组中,常会有重复的记录,比如手机号码,我们可以通过Hashtable来对其进行过滤
<div style="padding-right: 5.4pt; padding-left: 5.4pt; background: #e6e6e6 0% 50%; padding-bottom: 4px; width: 95%; padding-top: 4px;">http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gifpublic String[] checkArray(String[] str)...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        Hashtable<String, String> hash=new Hashtable<String, String>();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif        for(int i=0;i<str.length;i++)...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            if(!hash.containsKey(str))
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif                hash.put(str, str);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        Enumeration enumeration=hash.keys();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        String[] str_new=new String;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        int i=0;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif        while(enumeration.hasMoreElements())...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            str_new=enumeration.nextElement().toString();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            i++;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        return str_new;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif    }
页: [1]
查看完整版本: 散列过滤