Guava is the ice cream (essence) on the Java API cake.
a simple description of the source package:
Com.google.common.annotations: Common annotation type.
Com.google.common.base: Basic tool class libraries and interfaces.
Com.google.common.cache: Caching toolkit, a very easy-to-use and powerful in-JVM cache.
Com.google.common.collect: A collection interface with generics extension and implementation, as well as tool classes, where you'll find lots of fun collections.
Com.google.common.eventbus: Publish a subscription-style event bus.
Com.google.common.hash: Hash toolkit.
COM.GOOGLE.COMMON.IO:I/O Toolkit.
Com.google.common.math: Primitive arithmetic type and extra large number of arithmetic toolkit.
Com.google.common.net: Network toolkit.
Com.google.common.primitives: Eight static kits of primitive types and unsigned types.
Com.google.common.reflect: Reflection Kit.
Com.google.common.util.concurrent: Multithreading toolkit.
Now the classes for each package are now tested.
Com.google.common.base: Basic tools class libraries and interfaces
ASCII: For the processing of ASCII code, the more practical methods are:
tolowercase (String param): Handles the character of the incoming param as lowercase.
touppercase(String param): Handles the character of the incoming param as uppercase.
truncate (charsequence seq, int maxLength, String indicat OR): truncates the SEQ string to the Indicatori string, making the overall string length equal to MaxLength. If the maxlength is less than the indicator length, the error illegalargumentexception. If the maxlength is greater than the SEQ length, the result is seq.
Public classAsciiowntest { Public Static voidMain (string[] args) {String test=ascii.tolowercase ("ZHONG guo!"); SYSTEM.OUT.PRINTLN (test); Test=ascii.touppercase ("Feng ge"); SYSTEM.OUT.PRINTLN (test); //test=ascii.truncate ("Laoshiha", 3, "...."); This will be an error .//System.out.println (test);Test=ascii.truncate ("Laoshiha", 4, "....")); SYSTEM.OUT.PRINTLN (test); Test=ascii.truncate ("Laoshiha", 5, "....")); SYSTEM.OUT.PRINTLN (test); Test=ascii.truncate ("Laoshiha", 6, "....")); SYSTEM.OUT.PRINTLN (test); Test=ascii.truncate ("Laoshiha", 7, "....")); SYSTEM.OUT.PRINTLN (test); Test=ascii.truncate ("Laoshiha", 8, "....")); SYSTEM.OUT.PRINTLN (test); Test=ascii.truncate ("Laoshiha", 9, "....")); SYSTEM.OUT.PRINTLN (test); }}
The results are as follows:
Zhong guo! FENG Ge....l....la....lao....laoshihalaoshiha
Joiner: Used to stitch the elements in the container, this is still more practical.
On (String param): The delimiter is made according to Param.
Join (iterator<?> part): Used to stitch an element in an iterator, returning a string type
Append (a extend appendable,iterator<?> parts): Adds an element in an iterator behind a object.
Public classTest { Public Static voidMain (string[] args) {Joiner Joiner= Joiner.on (";"); List<String> lists =NewArraylist<string>(); Lists.add ("Hhaha"); Lists.add ("China Dragon"); System.out.println (Joiner.join (Lists.iterator ())); StringBuilder SB=NewStringBuilder (); Sb.append ("What does that mean?" "); SB=joiner.appendto (SB, lists); System.out.println (Sb.tostring ()); }
Hhaha: What does the Chinese dragon mean? Hhaha, China Dragon
Objects: Entity class
Equal (,): Verifies that two objects are equal.
Public Static void Main (string[] args) { System.out.println (objects.equal); }
True
Splitter: Splits a set of data by a character.
On (): delimiter.
Split (charsequence param): Split data.
Public class Test { publicstaticvoid main (string[] args) { Iterator< String> it = Splitter.on (","). Split ("Wo,xiang,ni"). iterator (); while (It.hasnext ()) { System.out.println (It.next ()); }}}
Results:
Woxiangni
Comparisonchain: Performs a comparison operation until a non-zero result is found, after which the comparison input is ignored.
classTestcompareImplementsComparable<testcompare>{ PrivateString hehe; Private intHeihei; PublicString Gethehe () {returnhehe; } Public voidSethehe (String hehe) { This. hehe =hehe; } @Override Public intcompareTo (Testcompare t) {returnComparisonchain.start (). Compare ( This. Hehe, T.hehe). Compare ( This. Heihei, T.heihei). result (); } }
Some summary of Guava