Java Collections 类的 emptyNavigableMap() 方法返回一个空的可导航映射,该映射是不可变的。
用法
以下是 emptyNavigableMap() 方法的声明:
public static final <K,V> NavigableMap<K,V> emptyNavigableMap()
参数
此方法不接受任何参数。
返回
emptyNavigableMap() 方法返回一个空的不可变 Navigable Map。
异常
NA
兼容版本
Java 1.8 及以上
例子1
import java.util.*;
public class CollectionsEmptyNavigableMapExample1 {
public static void main(String[] args) {
//Create an empty Map
NavigableMap<String,String> EmptyNavMap = Collections.emptyNavigableMap();
System.out.println("Created Empty Navigable Map:"+EmptyNavMap);
}
}
输出:
Created Empty Navigable Map:{}
例子2
import java.util.*;
public class CollectionsEmptyNavigableMapExample2 {
public static void main(String[] args) {
//Create an empty Map
NavigableMap<String,String> EmptyNavMap = Collections.emptyNavigableMap();
System.out.println("Created Empty Navigable Map:"+EmptyNavMap);
// try to add elements
EmptyNavMap.put("1","from JavaTpoint.com");
}
}
输出:
Created Empty Navigable Map:{} Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.Collections$UnmodifiableMap.put(Collections.java:1453) at myPackage.CollectionsEmptyNavigableMapExample2.main(CollectionsEmptyNavigableMapExample2.java:9)
例子3
import java.util.*;
public class CollectionsEmptyNavigableMapExample3 {
public static void main(String[] args) {
//Create an empty Map
NavigableMap<Integer, Integer> empNavMap = Collections.emptyNavigableMap();
empNavMap.put(1, 23424);
empNavMap.put(2, 65776);
System.out.println("Created empty immutable Navigable Map:"+empNavMap);
}
}
输出:
Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.Collections$UnmodifiableMap.put(Collections.java:1453) at myPackage.CollectionsEmptyNavigableMapExample3.main(CollectionsEmptyNavigableMapExample3.java:7)
相关用法
- Java Collections emptyNavigableSet()用法及代码示例
- Java Collections emptySet()用法及代码示例
- Java Collections emptySortedSet()用法及代码示例
- Java Collections emptyListIterator()用法及代码示例
- Java Collections emptyMap()用法及代码示例
- Java Collections emptySortedMap()用法及代码示例
- Java Collections emptyEnumeration()用法及代码示例
- Java Collections emptyIterator()用法及代码示例
- Java Collections emptyList()用法及代码示例
- Java Collections enumeration()用法及代码示例
- Java Collections synchronizedSortedSet()用法及代码示例
- Java Collections checkedQueue()用法及代码示例
- Java Collections unmodifiableNavigableSet()用法及代码示例
- Java Collections checkedSet()用法及代码示例
- Java Collections copy()用法及代码示例
- Java Collections checkedMap()用法及代码示例
- Java Collections synchronizedNavigableSet()用法及代码示例
- Java Collections singleton()用法及代码示例
- Java Collections fill()用法及代码示例
- Java Collections nCopies()用法及代码示例
注:本文由纯净天空筛选整理自 Java Collections emptyNavigableMap() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。