import java.util.ArrayList;
import java.util.Iterator;
public class Zyb2 {
public static void main(String[] args) {
ArrayList<Integer> a=new ArrayList<>();
a.add(1);
a.add(2);
a.add(3);
a.add(4);
a.add(5);
Iterator<Integer> ite=a.iterator();
while(ite.hasNext()) {
System.out.println(ite.next());
}
}
}
import java.util.ArrayList;
import java.util.Collections;
public class Zyb3fruit {
public static void main(String[] args) {
ArrayList<String> arr=new ArrayList<>();
arr.add("apple");
arr.add("grape");
arr.add("banana");
arr.add("pear");
String max = Collections.max(arr);
String min = Collections.min(arr);
System.out.println("最大元素为"+max+"最小元素为"+min);
}
}
import java.util.HashMap;
public class User {
private Integer id;
private String name;
private Integer money;
public User() {
super();
}
public User(Integer id, String name, Integer money) {
super();
this.id = id;
this.name = name;
this.money = money;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getMoney() {
return money;
}
public void setMoney(Integer money) {
this.money = money;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((money == null) ? 0 : money.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
User other = (User) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (money == null) {
if (other.money != null)
return false;
} else if (!money.equals(other.money))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}
import java.util.HashMap;
public class Usermain {
public static void main(String[] args) {
HashMap<Integer,User> users=new HashMap<>();
User u1=new User(1,"tom",20000);
User u2=new User(2,"marry",320000);
User u3=new User(3,"scott",20);
users.put(u1.getId(),u1);
users.put(u2.getId(),u2);
users.put(u3.getId(),u3);
User u=users.get(1);
System.out.println(u.getMoney());
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import test3.AgeComarator;
public class Zyx2main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
ArrayList<String> arr=new ArrayList<>();
for(int i=0;i<3;i++) {
System.out.println("输入一个字符串");
String s=input.nextLine();
arr.add(s);
}
Collections.sort(arr);
System.out.println(arr);
}
}