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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。