`
zhoujj303030
  • 浏览: 9672 次
  • 性别: Icon_minigender_1
  • 来自: 南昌
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

一个关于数组匹配的问题

阅读更多
  
private String[][] a = { { "", "a", "b", "c" }, { "a", "a", "b", "c" },
{ "b", "b", "c", "a" }, { "c", "b", "a", "c" } };

        怎么样判断数组a中红色部分的每一个元素都在棕色部分中!
分享到:
评论
1 楼 armorking 2008-07-29  

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;


public class SetTest
{
    public static void main(String[] args) 
    {
        String[] standard = {"", "a", "b", "c"};
        String[] target1 =   {"a", "a", "b", "c"};
        String[] target2 =   {"x", "a", "b", "c"};
        Set standardSet = new HashSet(Arrays.asList(standard));

        boolean result1 = standardSet.containsAll(Arrays.asList(target1));
        System.out.println("result1 : " + result1);

        boolean result2 = standardSet.containsAll(Arrays.asList(target2));
        System.out.println("result2 : " + result2);

    }
}


引用

result1 : true
result2 : false

相关推荐

Global site tag (gtag.js) - Google Analytics