fengsehng

# 代码：

## 负整数、零或正整数，根据此对象是小于、等于还是大于指定对象。

``````class Employee  implements Comparable<Employee>
{
public Employee(String n, double s)
{
name = n;
salary = s;
Random ID =  new Random();
id = ID.nextInt( 10000000 );
}
public int getId()
{
return id;
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public void raiseSalary( double byPercent)
{
double raise  = salary *byPercent/ 100 ;
salary+=raise;
}
public int compareTo(Employee other)
{
if (id<other.id) //这里比较的是什么 sort方法实现的就是按照此比较的东西从小到大排列
return - 1 ;
if (id>other.id)
return 1 ;
return 0 ;
}
private int id;
private String name;
private double salary;
}
``````

# 2)混排（Shuffling）

``````Collections.Shuffling(list)
double array[] = {112, 111, 23, 456, 231 };
for (int i = 0; i < array.length; i++) {
}
Collections.shuffle(list);
for (int i = 0; i < array.length; i++) {
System.out.println(li.get(i));
}
//结果：112,111,23,456,231``````

# 3) 反转(Reverse)

``````  使用Reverse方法可以根据元素的自然顺序 对指定列表按降序进行排序。
``````
``````Collections.reverse(list)
double array[] = {112, 111, 23, 456, 231 };
for (int i = 0; i < array.length; i++) {
}
Collections. reverse (list);
for (int i = 0; i < array.length; i++) {
System.out.println(li.get(i));
}
//结果：231,456,23,111,112``````

# 4) 替换所以的元素(Fill)

``````使用指定元素替换指定列表中的所有元素。
String str[] = {"dd","aa","bb","cc","ee"};
for(int j=0;j<str.length;j++){
}
Collections.fill(li,"aaa");
for (int i = 0; i < li.size(); i++) {
System.out.println("list[" + i + "]=" + li.get(i));

}
//结果：aaa,aaa,aaa,aaa,aaa``````

# 5) 拷贝(Copy)

``````Collections.copy(list,li): 后面一个参数是目标列表 ,前一个是源列表
double array[] = {112, 111, 23, 456, 231 };
List list = new ArrayList();
List li = new ArrayList();
for (int i = 0; i < array.length; i++) {
}
double arr[] = {1131,333};
String str[] = {"dd","aa","bb","cc","ee"};
for(int j=0;j<arr.length;j++){
}
Collections.copy(list,li);
for (int i = 0; i <list.size(); i++) {
System.out.println("list[" + i + "]=" + list.get(i));
}
//结果：1131,333,23,456,231``````

# 6) 返回Collections中最小元素(min)

``````Collections.min(list)
double array[] = {112, 111, 23, 456, 231 };
List list = new ArrayList();
for (int i = 0; i < array.length; i++) {
}
Collections.min(list);
for (int i = 0; i <list.size(); i++) {
System.out.println("list[" + i + "]=" + list.get(i));
}
//结果：23``````

# 7) 返回Collections中最大元素(max)

``````Collections.max(list)
double array[] = {112, 111, 23, 456, 231 };
List list = new ArrayList();
for (int i = 0; i < array.length; i++) {
}
Collections.max(list);
for (int i = 0; i <list.size(); i++) {
System.out.println("list[" + i + "]=" + list.get(i));
}
//结果：456``````

# 8) lastIndexOfSubList

``````int count = Collections.lastIndexOfSubList(list,li);
double array[] = {112, 111, 23, 456, 231 };
List list = new ArrayList();
List li = new ArrayList();
for (int i = 0; i < array.length; i++) {
}
double arr[] = {111};
String str[] = {"dd","aa","bb","cc","ee"};
for(int j=0;j<arr.length;j++){
}
Int locations = Collections. lastIndexOfSubList (list,li);
System.out.println(“===”+ locations);
//结果 3``````

# 9) IndexOfSubList

``````int count = Collections.indexOfSubList(list,li);
double array[] = {112, 111, 23, 456, 231 };
List list = new ArrayList();
List li = new ArrayList();
for (int i = 0; i < array.length; i++) {
}
double arr[] = {111};
String str[] = {"dd","aa","bb","cc","ee"};
for(int j=0;j<arr.length;j++){
}
Int locations = Collections.indexOfSubList(list,li);
System.out.println(“===”+ locations);
//结果 1``````

# 10) Rotate

``````Collections.rotate(list,-1);

double array[] = {112, 111, 23, 456, 231 };
List list = new ArrayList();
for (int i = 0; i < array.length; i++) {
}
Collections.rotate(list,-1);
for (int i = 0; i <list.size(); i++) {
System.out.println("list[" + i + "]=" + list.get(i));
}
//结果：111,23,456,231,112``````

# 欢迎关注《IT面试题汇总》微信订阅号。每天推送经典面试题和面试心得技巧

## 微信订阅号二维码如下：

### fengsehng

Dom解析： 在内存中创建一个DOM树，该结构通常需要加载整个文档然后才能做工作。由于它是基于信息层次的，因而DOM被认为是基于树或基于对象的，树在内存中是持久的，因此可以修改它以便应用程...

liujiest
2016/04/19
42
0

101ttyy
2017/10/10
0
0
XML的4中解析方式分析

Favour
2016/05/26
21
0

2015/09/30
1K
0
.NET 核心类库 - .NET Core

.NET Core（corefx）是微软 .NET 框架的核心类库，这是 .NET Foundation 项目的一部分。 .NET Core 包括以下组件： Immutable Collections； ECMA-335 Metadata Reader；支持低级的元数据查看...

2014/11/13
41.2K
5

Netty整合Protobuffer

13分钟前
9
0

BWH_Steven
32分钟前
3
0

1编写一个程序，提示用户输入名和姓，然后以“名,姓”的格式打印出来。 #include <stdio.h>#include <stdlib.h> int main(){ char firstName[20]; char lastName[20]; print......

1李嘉焘1
44分钟前
6
0

59分钟前
75
0
Docker 可视化管理 portainer

Moks角木

8
0