java10

7.

选择VectorStackHashTable,因为这些集合类是线程安全的;如果多个线程只是只读,应该选用线程不安全的集合类,因为它们效率较高。

8.

import java.util.*;
class ComplexNumber{
   int x, y;
ComplexNumber(int _x,int _y){
     x=_x;
     y=_y;
   }
}
public class TestSort{
   public static void main(String[] args){
	  
	   List list= new ArrayList();	  
	   list.add(new ComplexNumber(9,6));
	   list.add(new ComplexNumber(7,6));
	   list.add(new ComplexNumber(5,6));
	   list.add(new ComplexNumber(8,6));
	   list.add(new ComplexNumber(10,6));
	   Collections.sort(list,new Comparator(){ 
			public int compare(Object o1, Object o2){
				   ComplexNumber c1,c2;
				   c1 =(ComplexNumber)o1;
				   c2 = (ComplexNumber)o2;
				   return (c1.x-c2.x); 
			}
		});	   
	   for(int i=0;i<5;i++){
		   ComplexNumber c = (ComplexNumber)list.get(i);
		   System.out.println("ComplexNumber"+i+":x="+c.x+",yi="+c.y);
	   }
   }   
}

9.

不一定。

10.

import java.util.*;
public class UnifiedException
{    
	 private HashMap ht;
	 public UnifiedException(){
		 ht = new HashMap();		 
		 ht.put("/ by zero","发生了除数为零异常");
		 ht.put(null,"发生了空指针异常");
	 }
	 public void dealException(Exception e){		 
		String str = e.getMessage();
		System.out.println((String)ht.get(str));
	 }    	 
     public static void main(String[] args)
	{
	    int a,b,c;
	    try{
			a=67; b=0;
			//c=a/b;		
			throw new NullPointerException();
	     }
	     catch(Exception e){
	      //System.out.println(e.getMessage());
		  new UnifiedException().dealException(e);
	     }
	}    
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值