JDK 6 新功能

 
Java

Collections Framework Enhancements

This page summarizes enhancements to the collections framework in Java SE 6.

This release saw fewer API changes than 5.0, but there was more of a focus on the accuracy and clarity of the specification. We recommend using the Java SE 6 specification even when writing programs for older releases.

The primary theme of the API changes was better bi-directional collection access.

These new collection interfaces are provided:

  • Deque - a double ended queue, supporting element insertion and removal at both ends. Extends the Queue interface.
  • BlockingDeque - a Deque with operations that wait for the deque to become non-empty when retrieving an element, and wait for space to become available in the deque when storing an element. Extends both the Deque and BlockingQueue interfaces. (This interface is part of java.util.concurrent.)
  • NavigableSet - a SortedSet extended with navigation methods reporting closest matches for given search targets. A NavigableSet may be accessed and traversed in either ascending or descending order. This interface is intended to supersede the SortedSet interface.
  • NavigableMap - a SortedMap extended with navigation methods returning the closest matches for given search targets. A NavigableMap may be accessed and traversed in either ascending or descending key order. This interface is intended to supersede the SortedMap interface.
  • ConcurrentNavigableMap - a ConcurrentMap that is also a NavigableMap. (This interface is part of java.util.concurrent.)

The following concrete implementation classes have been added:

These existing classes have been retrofitted to implement new interfaces:

  • LinkedList - retrofitted to implement the Deque interface.
  • TreeSet - retrofitted to implement the NavigableSet interface.
  • TreeMap - retrofitted to implement the NavigableMap interface.

Two new methods were added to the Collections utility class:

  • newSetFromMap(Map) - creates a general purpose Set implementation from a general purpose Map implementation.

    There is no IdentityHashSet class, but instead, just use

    Set<Object> identityHashSet=
        Collections.newSetFromMap(
            new IdentityHashMap<Object, Boolean>());
    
  • asLifoQueue(Deque) - returns a view of a Deque as a Last-in-first-out (Lifo) Queue.
The Arrays utility class now has methods copyOf and copyOfRange that can efficiently resize, truncate, or copy subarrays for arrays of all types.

Before:

int[] newArray = new int[newLength];
System.arraycopy(oldArray, 0, newArray, 0, oldArray.length);

After:

int[] newArray = Arrays.copyOf(a, newLength);
 
 
 
 
 
 
 
 

Copyright © 2006 Sun Microsystems, Inc. All Rights Reserved.


Please send comments to: collections-comments@java.sun.com

 

 

 

 

 

 

 

 

 

 

Java

Enhancements in Java I/O

Contents


Enhancements in Java SE 6

java.io

One new class is provided:

  • Console - Contains methods to access a character-based console device. The readPassword() methods disable echoing thus they are suitable for retrieval of sensitive data such as passwords. The method System.console() returns the unique console associated with the Java Virtual Machine.

The following new methods were added to File:

Constructors were added to the following class:

The behavior of the following method was modified:

  • The File.isFile() Windows implementation has been modified to always return false for reserved device names such as CON, NUL, AUX, LPT, etc. Previously it returned true, which customers considered a bug because it was inconsistent with behavior for devices on Unix.

java.nio

  • A new java.nio.channels.SelectorProvider implementation that is based on the Linux epoll event notification facility is included. The epoll facility is available in the Linux 2.6, and newer, kernels. The new epoll-based SelectorProvider implementation is more scalable than the traditional poll-based SelectorProvider implementation when there are thousands of SelectableChannels registered with a Selector. The new SelectorProvider implementation will be used by default when the 2.6 kernel is detected. The poll-based SelectorProvider will be used when a pre-2.6 kernel is detected.
  • The system property sun.nio.ch.disableSystemWideOverlappingFileLockCheck controls whether java.nio.channels.FileChannel.lock() checks whether regions are locked by other instances of FileChannel. Unless this system property is set to true, FileChannel.lock() will throw an OverlappingFileLockException if an application attempts to lock a region that overlaps one that is locked by another instance of FileChannel. The system property exists to provide compatibility with previous releases which do not implement the JVM-wide overlapping file lock check.
Sun
Java Software
<script language=JavaScript src="/js/omi/jsc/s_code_remote.js"></script> <script language=JavaScript src="http://www-cdn.sun.com/share/metrics/metrics_group1.js"></script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值