有没有一种方法,我可以比较一个数组,像有没有一种方法可以比较数组和数组列表?
if (array[0]==arraylist[0])
一个ArrayList,我在这个问题上的工作:
String[] s= {"a","a","b","b","b","c"};
ArrayList<String> list = new ArrayList<String>();
list.add("a");
list.add("b");
list.add("c");
// create a new arraylist that stores the frequency of each character.
// For example, "a" appears twice in s, so newArrayList[0]=2; "b" appears
// three times, so newArrayList[1]=3, and so on.
我的想法是使用遍历字符串数组扫描和每次当它中的一个字母等于列表中的字母时,int count ++。但我不知道如何比较数组中的东西和数组列表中的东西。
你是一个有点含糊的比较应该是什么。它只是一个平等吗?或者你想知道更具体的东西。 – redge 2015-04-05 02:53:43
你甚至不能以这种方式比较两个数组(至少没有意义)。 – 2015-04-05 02:59:55
为什么混合数组和列表开始?当然可以*将两者进行比较,但通常会避免以这种方式混合和匹配它们的数据结构。 – Makoto 2015-04-05 03:19:49