本文整理匯總了Java中java.util.TreeSet.tailSet方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeSet.tailSet方法的具體用法?Java TreeSet.tailSet怎麽用?Java TreeSet.tailSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.TreeSet
的用法示例。
在下文中一共展示了TreeSet.tailSet方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testTailSetContents
import java.util.TreeSet; //導入方法依賴的package包/類
/**
* tailSet returns set with keys in requested range
*/
public void testTailSetContents() {
TreeSet set = set5();
SortedSet sm = set.tailSet(two);
assertFalse(sm.contains(one));
assertTrue(sm.contains(two));
assertTrue(sm.contains(three));
assertTrue(sm.contains(four));
assertTrue(sm.contains(five));
Iterator i = sm.iterator();
Object k;
k = (Integer)(i.next());
assertEquals(two, k);
k = (Integer)(i.next());
assertEquals(three, k);
k = (Integer)(i.next());
assertEquals(four, k);
k = (Integer)(i.next());
assertEquals(five, k);
assertFalse(i.hasNext());
SortedSet ssm = sm.tailSet(four);
assertEquals(four, ssm.first());
assertEquals(five, ssm.last());
assertTrue(ssm.remove(four));
assertEquals(1, ssm.size());
assertEquals(3, sm.size());
assertEquals(4, set.size());
}
示例2: testTailSetTreeSet
import java.util.TreeSet; //導入方法依賴的package包/類
@Test(expected = IllegalArgumentException.class)
public void testTailSetTreeSet() {
TreeSet<Integer> set = new TreeSet<Integer>();
set.add(1);
set.add(2);
set.add(3);
set.add(4);
set.add(5);
SortedSet<Integer> hs = set.tailSet(3);
hs.add(10);
assertThat(hs).containsExactly(3, 4, 5, 10);
set.remove(4);
assertThat(hs).containsExactly(3, 5, 10);
set.remove(3);
assertThat(hs).containsExactly(5, 10);
hs.add(-1);
}
示例3: set0
import java.util.TreeSet; //導入方法依賴的package包/類
private static NavigableSet set0() {
TreeSet set = new TreeSet();
assertTrue(set.isEmpty());
return set.tailSet(m1, false);
}