set

fatedgar 2011-12-27
下面俩断代码输出什么,为什么出现这样不通的结果?
一:
public static void main(String[] args)
	{
		 TreeSet<Integer> s = new TreeSet<Integer>(); 
		 TreeSet<Integer> subs = new TreeSet<Integer>(); 
		 for(int i=606; i<613; i++) 
		      if(i%2 == 0) s.add(i); 
		 subs = (TreeSet)s.subSet(608, true, 611, true); 
		 s.add(629); 
		 System.out.println(s + " " + subs); 

	}

二:
public static void main(String[] args)
	{
		 TreeSet<Integer> s = new TreeSet<Integer>(); 
		 TreeSet<Integer> subs = new TreeSet<Integer>(); 
		 for(int i=606; i<613; i++) 
		      if(i%2 == 0) s.add(i); 
		 subs = (TreeSet)s.subSet(608, true, 611, true); 
		 subs.add(629); 
		 System.out.println(s + " " + subs); 
	}
wendy_wxie 2012-01-09
第二个报错。。
subSet方法介绍:
The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range
Global site tag (gtag.js) - Google Analytics