检查List< String []>的最佳方法包含一个字符串[] [英] The best way to check if List<String[]> contains a String[]

查看:70
本文介绍了检查List< String []>的最佳方法包含一个字符串[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 List 声明为:

List<String[]> arrayList = new ArrayList<>();

List 包含多个 String s数组.

我需要检查此 ArrayList< String []> 中是否包含我拥有的 String [] .

I need to check if a String[] which I have is contained in this ArrayList<String[]>.

我目前正在遍历 ArrayList ,并将每个 String [] 与正在搜索的字符串进行比较:

I am currently iterating through the ArrayList and comparing each String[] with the one I am searching for:

for(String[] array: arrayList){
    if(Arrays.equals(array, myStringArray)){
        return true;
    }
}
return false;

有没有更好的方法来检查 ArrayList< String []> 是否包含特定的 String [] ?

Is there any better way to check if an ArrayList<String[]> contains a specific String[]?

推荐答案

实现的当前状态,它是一个 for 循环.

Array.equals() is the most efficient method afaik. That method alone meant for the purpose and optimized as less as it is in the current state of implementation which is a single for loop.

随它去吧

这篇关于检查List&lt; String []&gt;的最佳方法包含一个字符串[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆