注:调用此方法时需要根据自己的须由复写Objects的equals方法

创建复写了equals方法的对象类

public class Student {

    private String name;
private int age; public Student() {
} public Student(String name, int age) {
this.name = name;
this.age = age;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
} @Override
public boolean equals(Object obj) {
Student s = (Student) obj;
return this.name == s.name && this.age == s.age;
}
}

调用

import java.util.ArrayList;
import java.util.Collections;
import java.util.List; public class StudentTest {
public static void main(String[] args) {
List<Student> list = new ArrayList<Student>();
list.add(new Student("林青霞", 27));
list.add(new Student("风清扬", 30));
list.add(new Student("刘晓曲", 28));
list.add(new Student("武鑫", 29));
list.add(new Student("林青霞", 27)); int count=Collections.frequency(list, new Student("林青霞", 27));
System.out.println(count);
}
}

Java中Collections的frequency方法的更多相关文章

  1. Java中Collections的binarySearch方法

    方法一 public static <T> int binarySearch(List<? extends Comparable<? super T>> list, ...

  2. java中substring的使用方法

    java中substring的使用方法 str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字符串,将剩余字符串赋值给str: str ...

  3. Java中Set的contains()方法

    Java中Set的contains()方法 -- hashCode与equals方法的约定及重写原则 翻译人员: 铁锚 翻译时间: 2013年11月5日 原文链接: Java hashCode() a ...

  4. [java,2017-05-16] java中清空StringBuffer的方法以及耗费时间比较

    java中清空StringBuffer的方法,我能想到的有4种: 1. buffer.setLength(0);  设置长度为0 2. buffer.delete(0, buffer.length() ...

  5. java中BorderLayout的使用方法

    相关设置: 使用BorderLayout布局上下左右中布局5个按键,单击中间的那个按键时就关闭窗口 代码: /**** *java中BorderLayout的使用方法 * 使用BorderLayout ...

  6. 【Java】Java中常用的String方法

    本文转载于:java中常用的String方法 1 length()字符串的长度 String a = "Hello Word!"; System.out.println(a.len ...

  7. Java中Set的contains()方法——hashCode与equals方法的约定及重写原则

    转自:http://blog.csdn.net/renfufei/article/details/14163329 翻译人员: 铁锚 翻译时间: 2013年11月5日 原文链接: Java hashC ...

  8. java中equals和hashCode方法随笔二

    前几天看了篇关于java中equals和hashCode方法的解析 1.Object类中的equals方法和hashCode方法. Object类中的equals和hashCode方法简单明了,所有的 ...

  9. java中static变量和方法的总结

    转自:http://blog.csdn.net/haobo920/article/details/5921621 java中static变量和方法的总结 java中一切皆是对象 一个类中对象的定义一般 ...

随机推荐

  1. MPP(大规模并行处理)

    1. 什么是MPP? MPP (Massively Parallel Processing),即大规模并行处理,在数据库非共享集群中,每个节点都有独立的磁盘存储系统和内存系统,业务数据根据数据库模型和 ...

  2. No module named 'PyQt5.sip'

    使用pyinstaller打包python文件为windows可执行程序可能遇到的问题 pyinstaller yourprogram.py打包的程序双击打开一闪而过,提示上面标题的错误 把pycom ...

  3. cf978E Bus Video System

    The busses in Berland are equipped with a video surveillance system. The system records information ...

  4. Android 渗透小知识点

    客户端用于 ADB 通信的默认端口始终是 5037,设备使用从 5555 到 5585 的端口 adb devices用于显示所有已连接设备, 有时候会出现一些问题, 这时候需要使用adb kill- ...

  5. JAVA-数组或集合

    哈哈,今天我们来讲解一下有关于一些数组 或者是集合的知识点 1.ArrayList,LinkedList,Vector的区别 ArrayList,LinkedList,Vector都是实现List接口 ...

  6. HDFS HA 的 hdfs-site.xml

    <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <!-- Licens ...

  7. android onNewIntent 为什么要在onNewIntent的时候要显示的去调用setIntent

    原因: 当调用到onNewIntent(intent)的时候,需要在onNewIntent() 中使用setIntent(intent)赋值给Activity的Intent.否则,后续的getInte ...

  8. HTTP的缓存控制

    1.缓存的分类: (1)缓存分为服务端侧(server side,比如 Nginx.Apache)和客户端侧(client side,比如 web browser). (2)服务端缓存又分为 代理服务 ...

  9. 《数据结构》C++代码 栈与队列

    线性表中,先进先出的叫队列,先进后出的叫栈.队列常用于BFS,而在函数递归层数过高时,需要手动实现递归过程,这时候便需要写一个“手动栈”. 有时候,我们会有大量数据频繁出入队列,但同时存在其内的元素却 ...

  10. linux运维笔记

    一.查找大文件 sudo find / -size +100M -exec ls -lh {} \;