将数组反转
package
com;
import
java.util.ArrayList;
import
java.util.Collections;
import
java.util.List;
public
class
CollectionText {
public
static
void
main(String[]
args
) {
List<Student>
list
=
new
ArrayList<Student>();
list
.add(
new
Student(5,
"胡汉一"
, 55));
list
.add(
new
Student(9,
"胡汉三"
, 75));
list
.add(
new
Student(1,
"胡汉八"
, 65));
list
.add(
new
Student(8,
"胡汉四"
, 85));
//反转
Collections.
reverse
(
list
);
for
(Student
s
:
list
) {
System.
out
.println(
s
);
}
}
}
随机排序
package
com;
import
java.util.ArrayList;
import
java.util.Collections;
import
java.util.List;
public
class
CollectionText {
public
static
void
main(String[]
args
) {
List<Student>
list
=
new
ArrayList<Student>();
list
.add(
new
Student(5,
"胡汉一"
, 55));
list
.add(
new
Student(9,
"胡汉三"
, 75));
list
.add(
new
Student(1,
"胡汉八"
, 65));
list
.add(
new
Student(8,
"胡汉四"
, 85));
//反转
// Collections.reverse(list);
Collections.
shuffle
(
list
);
for
(Student
s
:
list
) {
System.
out
.println(
s
);
}
}
}