2021.03.10
第30次记录
**课堂笔记:**
1.Collection集合的contains方法
boolean contains(Object o)
判断集合中是否包含某个对象o,如果包含返回true,不包含返回false
2.contains方法是用来判断集合中是否包含某个元素的方法,那么它在底层
是怎么判断集合中是否包含某个元素的呢?
调用了equals方法进行比对。
equals方法返回true,就表示包含这个元素。
**代码演示:**
```java
public class CollectionText04 {
public static void main(String[] args) {
Collection c = new ArrayList();
String s1 = new String("ab");
String s2 = new String("ac");
c.add(s1);
c.add(s2);
System.out.println("元素个数:" + c.size());
String s3 = new String("ab");
System.out.println(c.contains(s3));
}
}
```
输出结果:
元素个数:2
true
相关文章
- 01-28Leetcode 219. Contains Duplicate II
- 01-28[Leetcode]220. Contains Duplicate III
- 01-28220. Contains Duplicate III
- 01-28LeetCode217 Contains Duplicate
- 01-28LeetCode-220 Contains Duplicate III
- 01-28visual studio 关于 Updates were rejected because the remote contains work that you do
- 01-28LINQ to SQL语句(7)之Exists/In/Any/All/Contains
- 01-28contains non-ASCII characters doesn't have an encoding declaration at the top.
- 01-28[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated
- 01-28运行报错Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column xx....