当前位置: 代码迷 >> J2SE >> 数组比较有关问题
  详细解决方案

数组比较有关问题

热度:55   发布时间:2016-04-24 13:19:55.0
数组比较问题?
现在有这样一个问题我用到一个数组String[] str ={ACBDB};和char[]key = {ABCDE};现在问题出现在怎么能比较出两个数组中相等的值有几个?

我想了好长时间了,可就是没什么头绪,希望大家帮我解决一下,十分感谢!!

------解决方案--------------------
Java code
/** * project_name: Test * package_name: netsource * package_declaration: package netsource; * filename: CompareArray.java * author: yuhaiming * date: 2007-11-15 */package netsource;public class CompareArray {    public static void disposal(){        String[] array = {"a","b","c","d","e"};        char[] chs = {'a','c','f','e'};        int count =0;        String curstr = "";         for(int i=0;i<chs.length;i++){                        curstr = String.valueOf(chs[i]);            for(int j=0;j<array.length;j++){                if(curstr.equals(array[j]))                    count++;                    continue;            }                    }        System.out.println("相等的有"+count+"个");    }    /**     * @param args     */    public static void main(String[] args) {        // TODO Auto-generated method stub        disposal();    }}
  相关解决方案