Google Guava (14.0) Part1
来源:互联网 发布:抽奖软件制作 编辑:程序博客网 时间:2024/06/05 07:11
Install
JSR-305 JAR is used for detecting defects and only when wanted to be used, it need to explicitly define that dependency. Attention, when using Guava in Scala, you have to include the jar.
While the Java compiler does not require the library
containing the annotations when compiling, the Scala compiler currently does.
Utilities that help deal with some of the common tasks in programming.
Joiner
Concatenate strings together with a specified delimiter.
Joiner stringJoiner = Joiner.on("|").skipNulls();stringJoiner.join("foo", "bar", null);
Once created, a join class is immutable. so it doesn’t work when you code like this stringJoiner.useForNull("missing")
Joiner class also can work with StringBuilder/FileWriter helping appending by using joiner.appentTo()
, it returns the preceding instance.
MapJoiner
Joiner mapJoiner = Joiner.on("#").withKeyValueSeperator("=");String test = mapJoiner.join(testMap);
Splitter
Take a string with some delimiter character and split that string on the delimiter and obtain an array of the parts of the strings.
Splitter is also immutable on creation.
Splitter.on("|").split("foo|bar|baz");Splitter splitter = Splitter.on("\\d+");Splitter splitter = Splitter.on("|").trimResults();
A Splitter class can split on a single character, a fixed string, a java.util.regex.Pattern
package or a CharMatcher class.
MapSplitter
Splitter.on("#").withKeyValueSeparator("=").split(string);
CharUtils
These classes all help work with strings.
Charsets
Use Charsets to specify character sets of returning byte, but now no worth when Java 7 has provided StandardCharsets class.
Strings
padEnd/padStart
insert character to the string in front or the end until meeting the minimum length. Attention, if the provided string already had met length, no paddding.
nullToEmpty emptyToNull isNullOrEmpty
, method name tells.
CharMatcher
Help work with characters based on the presence or absence of characters.
Unlike Joiner and Splitter, CharMatcher can be combined to a new class.
CharMatcher.BREAKING_WHITESPACE.replaceFrom(string, ' ');CharMatcher.WHITESPACE.collapseFrom/trimAndCollapseFrom(string, ' ');CharMatcher.JAVA_DIGIT.retainFrom(string) //retain deigit
Preconditions
checkNotNull(obj, errMsg)checkElementIndex(index, size, errMsg)checkArgument(expression, errMsg)checkState(expression, errMsg) //expression for obj
As name tells.
Object
Object.toStringHelper(this).omitNullValues().add(string, property).toString();Object.firstNotNull(string, defaultString);ComparisonChain.start().compare()...result();
- Google Guava (14.0) Part1
- Google Guava (14.0) Part2
- Google guava
- Google Guava
- google guava
- google guava
- Google Guava
- Google Guava快速入门
- Google guava 库
- google工具类guava
- Google Guava Collections
- google Guava简介
- google guava简单使用
- 关于Google Guava
- Google Guava Collections
- Google Guava Collection实例
- Google Guava学习笔记
- Google Guava入门教程
- Nginx的安装与配置(PHP)
- 17
- Java代码规范
- HashMap使用
- 网络编程---HTTP协议加强
- Google Guava (14.0) Part1
- Ionic2自定义组件的使用
- 内核栈和用户栈
- oracle体系结构和用户管理
- linux/aix系统下,websphere服务ear包备份
- C#操作Excel类,功能比较全
- 22.Generate Parentheses
- 虚拟机linux中jdk配置及其安装
- 理解PHP网页运行原理