java集合框架(习题与答案)资料

public Account(){}

public Account(double balance,String password){

this.id=new Random().nextLong();

this.balance=balance;

this.password=password;

}

public long getId() {

return id;

}

public void setId(long id) {

this.id = id;

}

public double getBalance() {

return balance;

}

public void setBalance(double balance) {

this.balance = balance;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

}

20. *(List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列。 例如:

List list = new ArrayList(); list.add(“Hello”); list.add(“World”);

list.add(“Learn”); //此时list 为Hello World Learn reverseList(list);

//调用reverseList 方法之后,list 为Learn World Hello 21. **(Map,Hash 算法)有如下代码: import java.util.*; class MyKey{ int keyValue;

public MyKey(){}

public MyKey(int value){this.keyValue = value;} }

class MyValue{ String value;

public MyValue(){}

public MyValue(String value){this.value = value;} public String toString(){return value;} }

public class TestMap{

public static void main(String args[]){ Map map = new HashMap(); MyKey key1 = new MyKey(10); map.put(key1, new MyValue(“abc”));

map.put(new MyKey(10), new MyValue(“cde”)); System.out.println(map.get(key1)); System.out.println(map.size()); } }

写出该代码的输出结果。abc 2

22. **(Id,hashCode,equals)为Worker 类增加id 属性,用来唯一标识一

>>鐏炴洖绱戦崗銊︽瀮<<
12@gma联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4