package io.jcwl.modules.drives.controller;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by lenovo on 2018/5/27.
//要使用jdk1.8编译
*/
public class Texo {
private Integer
age =
14
;
class Status{
private Integer
age
;
String
name
;
public Integer
getAge() {
return
age
;
}
public void
setAge(Integer age) {
this.
age = age
;
}
public String
getName() {
return
name
;
}
public void
setName(String name) {
this.
name = name
;
}
@Override
public boolean
equals(Object o) {
if (
this == o)
return true;
if (o ==
null || getClass() != o.getClass())
return false;
Status person = (Status) o
;
if (!
age.equals(person.
age))
return false;
return
name.equals(person.
name)
;
}
@Override
public int
hashCode() {
int result =
age.hashCode()
;
result =
31 * result +
name.hashCode()
;
return result
;
}
public void
print() {
int age =
14
;
System.
out.println(
"局部变量:" + age)
;
System.
out.println(
"内部类变量:" +
this.
age)
;
System.
out.println(
"外部类变量:" + Texo.
this.
age)
;
} }
public static void
main(String[] arg ){ Texo.Status in =
new Texo().
new Status()
;
in.print()
;
List<Texo.Status> statuses=
new ArrayList<Texo.Status>()
;
Texo.Status status=
new Texo().
new Status()
;
status.setAge(
2)
;
status.setName(
"zhangsan")
;
statuses.add(status)
;
Texo.Status status3=
new Texo().
new Status()
;
status3.setAge(
1)
;
status3.setName(
"lisi")
;
statuses.add(status3)
;
Texo.Status status4=
new Texo().
new Status()
;
status4.setAge(
3)
;
status4.setName(
"wangwu")
;
statuses.add(status4)
;
Texo.Status status5=
new Texo().
new Status()
;
status5.setAge(
3)
;
status5.setName(
"wangwu")
;
statuses.add(status5)
;
for (Texo.Status status1:statuses){ System.
out.println(
"排序前"+status1.getName()+
","+status1.getAge())
;
} statuses.sort((Texo.Status h1
, Texo.Status h2) -> h1.getName().compareTo(h2.getName()))
;
for (Texo.Status status1:statuses){ System.
out.println(
"排序后"+status1.getName()+
","+status1.getAge())
;
}
// 去重
List<Texo.Status> personList =
new ArrayList<Texo.Status>()
;
statuses.stream().forEach( p -> {
if (!
personList.contains(p)) {
personList.add(p)
;
} } )
;
System.
out.println(personList)
;
for (Texo.Status status1:personList){ System.
out.println(
"Status去重后"+status1.getName()+
","+status1.getAge())
;
} List<String> it =
new ArrayList<String>()
;
it.add(
"1")
;
it.add(
"3")
;
it.add(
"2")
;
it.add(
"2")
;
for (String i:it){ System.
out.println(
"排序前"+i)
;
} Collections.
sort(it
, (s1
, s2) -> s1.compareTo(s2))
;
for (String i:it){ System.
out.println(
"排序后"+i)
;
} List<String> its=it.stream().distinct().collect(Collectors.
toList())
;
for (String i:its){ System.
out.println(
"去重后"+i)
;
} }}