Java ArrayList??????????
???????????? ???????[ 2016/1/21 14:01:04 ] ??????????????? Java
??????????????????У??????????? ArrayList ??????????? 5 ?????????????? 5 ??????????????????? getArrayList()??sortAscending()?? sortDescending()?????????????Щ????????? ArrayList ????
??????????£?
????-------------------------------------------------------
????T E S T S
????-------------------------------------------------------
????Running guru.springframework.blog.sortarraylist.ascendingdescending.SortArrayListAscendingDescendingTest
????Unsorted ArrayList: [France?? USA?? India?? Spain?? England]
????Sorted ArrayList in Ascending Order : [England?? France?? India?? Spain?? USA]
????Sorted ArrayList in Descending Order: [USA?? Spain?? India?? France?? England]
????Tests run: 1?? Failures: 0?? Errors: 0?? Skipped: 0?? Time elapsed: 0.001 sec - in guru.springframework.blog.sortarraylis
???????????????????? ArrayList ?????????????????????????? Collections.sort()???????????????????? ArrayList ???????????????????????????????Щ?????????? ArrayList ????????
????Collections.sort() ?????? ArrayList ?????????κ????? List ???????????????????????????ζ????Щ???????????? java.lang ???е? Comparable ???????? String ??????? Comparable ?????????????????????? ArrayList ??????Щ???????? Java ??????? Comparable ???????????????????? Integer??Short??Double??Float??Boolean??BigInteger??BigDecimal??File ?? Date ??????? Comparable ????
???????Comparable????ArrayList
????Comparable ????е?? compareTo()????????????????? Comparable ?????????????????????????????б?????? Comparable ???????????д compareTo()?????????????????????????????????????????????????????????????????????compareTo()????????Int????????????????????????壺
?????????????????????? comPareTO()??????
?????????????????????? comPareTO()?????С
???????????????????
??????????????????????JobCandidate ?????????? ArrayList ?в???????????????JobCandidate ??????????????????????????????????????????????????????????? ArrayList ?е? JobCandidate ??????????????????????????? JobCandidate ????? Comparable ??????д compareTo()??????
????The code of the JobCandidate class is this.
????JobCandidate?????????£?
????JobCandidate.java
package guru.springframework.blog.sortarraylist.comparable;
public class JobCandidate implements Comparable {
private String name;
private String gender;
private int age;
public JobCandidate(String name?? String gender?? int age) {
this.name = name;
this.gender = gender;
this.age = age;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public int getAge() {
return age;
}
@Override
public int compareTo(JobCandidate candidate) {
return (this.getAge() < candidate.getAge() ? -1 :
(this.getAge() == candidate.getAge() ? 0 : 1));
}
@Override
public String toString() {
return " Name: " + this.name + "?? Gender: " + this.gender + "?? age:" + this.age;
}
}
?????????? JobCandidate ????д?? compareTo()?????У???????????????????????????????????????(this.getAge() – candidate.getAge())????????????????????????? return ??俴????????????????????????????????????????????????????????????????£???????????????????????????????????????????????Щ??????????????????????????????????????????????????????????????????????к???????????????????д????????????з???????? JobCandidate ???? ArrayList ???????????
????JobCandidateSorter.java
package guru.springframework.blog.sortarraylist.comparable;
import java.util.ArrayList;
import java.util.Collections;
public class JobCandidateSorter {
ArrayList jobCandidate = new ArrayList<>();
public JobCandidateSorter(ArrayList jobCandidate) {
this.jobCandidate = jobCandidate;
}
public ArrayList getSortedJobCandidateByAge() {
Collections.sort(jobCandidate);
return jobCandidate;
}
}
?????? JobCandidateSorter ???У?????????????? ArrayList ??????з????????????????? JobCandidateSorter ??????????д?? getSortedJobCandidateByAge()????????????????У???????? Collections.sort()????????????????? ArrayList ????????????????? ArrayList??
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????