本文整理汇总了Java中java.util.TreeSet.subSet方法的典型用法代码示例。如果您正苦于以下问题:Java TreeSet.subSet方法的具体用法?Java TreeSet.subSet怎么用?Java TreeSet.subSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.TreeSet
的用法示例。
在下文中一共展示了TreeSet.subSet方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSubSetContents2
import java.util.TreeSet; //导入方法依赖的package包/类
public void testSubSetContents2() {
TreeSet set = set5();
SortedSet sm = set.subSet(two, three);
assertEquals(1, sm.size());
assertEquals(two, sm.first());
assertEquals(two, sm.last());
assertFalse(sm.contains(one));
assertTrue(sm.contains(two));
assertFalse(sm.contains(three));
assertFalse(sm.contains(four));
assertFalse(sm.contains(five));
Iterator i = sm.iterator();
Object k;
k = (Integer)(i.next());
assertEquals(two, k);
assertFalse(i.hasNext());
Iterator j = sm.iterator();
j.next();
j.remove();
assertFalse(set.contains(two));
assertEquals(4, set.size());
assertEquals(0, sm.size());
assertTrue(sm.isEmpty());
assertFalse(sm.remove(three));
assertEquals(4, set.size());
}
示例2: populatedSet
import java.util.TreeSet; //导入方法依赖的package包/类
/**
* Returns a new set of given size containing consecutive
* Integers 0 ... n - 1.
*/
private static NavigableSet<Integer> populatedSet(int n) {
TreeSet<Integer> q = new TreeSet<>();
assertTrue(q.isEmpty());
for (int i = n - 1; i >= 0; i -= 2)
assertTrue(q.add(new Integer(i)));
for (int i = (n & 1); i < n; i += 2)
assertTrue(q.add(new Integer(i)));
assertTrue(q.add(new Integer(-n)));
assertTrue(q.add(new Integer(n)));
NavigableSet s = q.subSet(new Integer(0), true, new Integer(n), false);
assertFalse(s.isEmpty());
assertEquals(n, s.size());
return s;
}
示例3: treeSubSetMethod
import java.util.TreeSet; //导入方法依赖的package包/类
public static void treeSubSetMethod(){
//sub set is not populating - not sure why
//http://www.tutorialspoint.com/java/util/treeset_subset.htm
Integer[] nums = {12,46,52,34,87,123,14,44};
TreeSet <Integer> fullNumsList = new TreeSet<Integer>(new ArrayList<>(Arrays.asList(nums)));
TreeSet <Integer> partNumsList = new TreeSet<Integer>();
out.println("Original List: " + fullNumsList.toString());
partNumsList = (TreeSet<Integer>) fullNumsList.subSet(1,3);
out.println("SubSet of List: " + partNumsList.toString());
out.println(partNumsList.size());
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:16,代码来源:SimpleSubsetting.java
示例4: testSubSetContents
import java.util.TreeSet; //导入方法依赖的package包/类
/**
* subSet returns set with keys in requested range
*/
public void testSubSetContents() {
TreeSet set = set5();
SortedSet sm = set.subSet(two, four);
assertEquals(two, sm.first());
assertEquals(three, sm.last());
assertEquals(2, sm.size());
assertFalse(sm.contains(one));
assertTrue(sm.contains(two));
assertTrue(sm.contains(three));
assertFalse(sm.contains(four));
assertFalse(sm.contains(five));
Iterator i = sm.iterator();
Object k;
k = (Integer)(i.next());
assertEquals(two, k);
k = (Integer)(i.next());
assertEquals(three, k);
assertFalse(i.hasNext());
Iterator j = sm.iterator();
j.next();
j.remove();
assertFalse(set.contains(two));
assertEquals(4, set.size());
assertEquals(1, sm.size());
assertEquals(three, sm.first());
assertEquals(three, sm.last());
assertTrue(sm.remove(three));
assertTrue(sm.isEmpty());
assertEquals(3, set.size());
}
示例5: set5
import java.util.TreeSet; //导入方法依赖的package包/类
/**
* Returns a new set of first 5 ints.
*/
private static NavigableSet set5() {
TreeSet q = new TreeSet();
assertTrue(q.isEmpty());
q.add(one);
q.add(two);
q.add(three);
q.add(four);
q.add(five);
q.add(zero);
q.add(seven);
NavigableSet s = q.subSet(one, true, seven, false);
assertEquals(5, s.size());
return s;
}