Java Collections emptyNavigableSet()
emptyNavigableSet() 获取不可变的空NavigableSet。
1 语法
public static <E> NavigableSet<E> emptyNavigableSet()
2 参数
无
3 返回值
返回不可变的空NavigableSet。
4 Collections emptyNavigableSet()示例1
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* Java Collections.emptyNavigableSet的例子
*/
import java.util.*;
public class Demo {
public static void main(String[] args) {
//Create an empty Set
NavigableSet<String> EmpNavSet = Collections.<String>emptyNavigableSet();
System.out.println("Empty Navigable Set: "+EmpNavSet);
}
}
输出结果为:
Empty Navigable Set: []
5 Collections emptyNavigableSet()示例2
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* Java Collections.emptyNavigableSet的例子
*/
import java.util.*;
public class Demo {
public static void main(String[] args) {
//Create an empty Navigable Set
NavigableSet<String> EmpNavSet = Collections.emptyNavigableSet();
System.out.println("Created empty immutable Navigable Set: "+EmpNavSet);
//Try to add elements
EmpNavSet.add("A");
EmpNavSet.add("B");
}
}
输出结果为:
Exception in thread "main" java.lang.UnsupportedOperationException
Created empty immutable Navigable Set: []
at java.util.Collections$UnmodifiableCollection.add(Collections.java:1055)
at com.yiidian.Demo.main(Demo.java:18)
6 Collections emptyNavigableSet()示例3
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* Java Collections.emptyNavigableSet的例子
*/
import java.util.*;
public class Demo {
public static void main(String[] args) {
//Create an empty Navigable Set
Set<Integer> empNavSet = Collections.emptyNavigableSet();
empNavSet.add(1);
empNavSet.add(2);
System.out.println("Created empty immutable Navigable Set: "+empNavSet);
}
}
输出结果为:
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableCollection.add(Collections.java:1055)
at com.yiidian.Demo.main(Demo.java:16)
热门文章
优秀文章