Skip to content

Commit 563d447

Browse files
committed
如何判断数组Array是否包含指定的值
1 parent bad8392 commit 563d447

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ stackoverflow-Java-top-qa
1414
* [将数组转换为List](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/create-arraylist-arraylistt-from-array-t.md)
1515
* [如何遍历map对象](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/iterate-through-a-hashmap.md)
1616
* [public,protected,private,不加修饰符。有什么区别呢?](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/in-java-whats-the-difference-between-public-default-protected-and-private.md)
17+
* [如何判断数组Array是否包含指定的值?](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/in-java-whats-the-difference-between-public-default-protected-and-private.md)
1718

1819
> 代码规范
1920
@@ -44,9 +45,10 @@ stackoverflow-Java-top-qa
4445
-
4546

4647
- [Why does this code using random strings print “hello world”?](http://stackoverflow.com/questions/15182496/why-does-this-code-using-random-strings-print-hello-world)
47-
- [Iterate over each Entry in a Map](http://stackoverflow.com/questions/46898/iterate-over-each-entry-in-a-map)
48+
-
4849
- [How can I create an executable jar with dependencies using Maven?](http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven)
4950
- [How to avoid Java code in JSP files?](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files)
51+
-
5052
- [In Java, how can I test if an Array contains a certain value?](http://stackoverflow.com/questions/1128723/in-java-how-can-i-test-if-an-array-contains-a-certain-value)
5153
- [Why is executing Java code in comments with certain Unicode characters allowed?](http://stackoverflow.com/questions/30727515/why-is-executing-java-code-in-comments-with-certain-unicode-characters-allowed)
5254
- [Dealing with “java.lang.OutOfMemoryError: PermGen space” error](http://stackoverflow.com/questions/88235/dealing-with-java-lang-outofmemoryerror-permgen-space-error)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
##如何判断数组Array是否包含指定的值
2+
3+
1. Arrays.asList(...).contains(...)
4+
5+
2. 使用 Apache Commons Lang包中的ArrayUtils.contains
6+
7+
8+
```java
9+
String[] fieldsToInclude = { "id", "name", "location" };
10+
11+
if ( ArrayUtils.contains( fieldsToInclude, "id" ) ) {
12+
// Do some stuff.
13+
}
14+
```
15+
16+
stackoverflow链接:
17+
http://stackoverflow.com/questions/1128723/in-java-how-can-i-test-if-an-array-contains-a-certain-value

0 commit comments

Comments
 (0)