JDK8至JDK 11 常用API更新
文章目录
1) Optional
新增:
stream()ifPresentOrElse(Consumer<? super T> action, Runnable emptyAction)or(Supplier<? extends Optional<? extends T>> supplier)版本: 9
orElseThrow()版本: 10
isEmpty()版本: 11
2) CompletableFuture
新增:
completeOnTimeout(T value, long timeout, TimeUnit unit)newIncompleteFuture()defaultExecutor()copy()minimalCompletionStage()completeAsync(Supplier<? extends T> supplier, Executor executor)orTimeout(long timeout, TimeUnit unit)delayedExecutor(long delay, TimeUnit unit, Executor executor)delayedExecutor(long delay, TimeUnit unit)completedStage(U value)failedFuture(Throwable ex)failedStage(Throwable ex)版本: 9
3) Stream
新增:
takeWhile(Predicate<? super T> predicate)dropWhile(Predicate<? super T> predicate)ofNullable(T t)iterate(T seed, Predicate<? super T> hasNext, UnaryOperator<T> next)版本: 9
4) Map
新增:
of() 系列方法entry(K k, V v)版本: 9
copyOf(Map<? extends K,? extends V> map)版本: 10
5) List
新增:
of() 系列方法版本: 9
copyOf(Collection<? extends E> coll)版本: 10
6) Set
新增:
of() 系列方法版本: 9
copyOf(Collection<? extends E> coll)版本: 10
7) LocalDate
新增:
datesUntil(LocalDate endExclusive)datesUntil(LocalDate endExclusive, Period step)toEpochSecond(LocalTime time, ZoneOffset offset)版本: 9
8) Locale
新增:
getISOCountries(Locale.IsoCountryCode type)版本: 9
9) String
新增:
strip()stripLeading()stripTrailing()isBlank()lines()repeat(int count)版本: 11
chars()codePoints()版本: 9
10) HttpClient
新增类
版本: 11
11) InputStream
新增:
nullInputStream()readNBytes(int len) throws IOException版本: 11
readAllBytes() throws IOExceptionreadNBytes(byte[] b, int off, int len) throws IOExceptiontransferTo(OutputStream out) throws IOException版本: 9
12) OutputStream
新增:
nullOutputStream()版本: 11
13) ByteArrayOutputStream
新增:
writeBytes(byte[] b)版本: 11
toString(Charset charset)版本: 10
14) Selector
新增:
select(Consumer<SelectionKey> action, long timeout) throws IOExceptionselect(Consumer<SelectionKey> action) throws IOExceptionselectNow(Consumer<SelectionKey> action) throws IOException版本: 11
15) Objects
新增:
requireNonNullElse(T obj, T defaultObj)requireNonNullElseGet(T obj, Supplier<? extends T> supplier)checkIndex(int index, int length)checkFromToIndex(int fromIndex, int toIndex, int length)checkFromIndexSize(int fromIndex, int size, int length)版本: 9
16) Path
新增:
of(String first, String... more)of(URI uri)版本: 11
17) Files
新增:
readString(Path path) throws IOExceptionreadString(Path path, Charset cs) throws IOExceptionwriteString(Path path, CharSequence csq, OpenOption... options) throws IOExceptionwriteString(Path path, CharSequence csq, Charset cs, OpenOption... options) throws IOException版本: 11
18) Socket
新增:
setOption(SocketOption<T> name, T value) throws IOExceptiongetOption(SocketOption<T> name) throws IOExceptionsupportedOptions()版本: 9
19) HttpURLConnection
新增:
setAuthenticator(Authenticator auth)版本: 9
20) URLClassLoader
新增:
URLClassLoader(String name, URL[] urls, ClassLoader parent)URLClassLoader(String name, URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory)版本: 9
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论