"Guava" Joiner, splitter source

Source: Internet
Author: User
Tags iterable
JoinerFunction: To stitch multiple objects into a string SampleJoiner Joiner = Joiner.on (";").         Skipnulls (); Return Joiner.join (Bpeapplication, Pipeline, devicename, field); Source Code   /**    * returns a joiner which automatically places  {@code  separator} between consecutive elements.    */  public static joiner on (string separator)  {     return new joiner (separator); &NBSP;&NBSP}   /**    * Returns a string containing the  string representation of each argument, using the previously     * configured separator between each.    */  public final string join (@Nullable  object first,   @Nullable  object second, object... rest)  {    return  Join (Iterable (first, second, rest)); &NBSP;&NBSP}   public final string join (iterable<?> parts)  {&Nbsp;   return join (Parts.iterator ()); &NBSP;&NBSP}   public final string join (iterator<?> parts)  {     return appendto (New stringbuilder (),  parts). toString (); &NBSP;&NBSP}   public final string join (iterator<?> parts)  {     return appendto (New stringbuilder (),  parts). toString (); &NBSP;&NBSP}     public <a extends appendable> a appendto (A  Appendable, iterator<?> parts)  throws ioexception {     Checknotnull (appendable);     if  (Parts.hasnext ())  {      appendable.append ( ToString (Parts.next ()));       while  (Parts.hasnext ())  {         appendable.append (separator);   &nBsp;     appendable.append (ToString (Parts.next ()));       }          return appendable;   } SplitterThe splitter provides joiner corresponding functionality. SampleSplitter.on (', '). Split ("Foo,bar") returns: This invocation returns a iterable<string> containing "foo" and "Bar", in That order.

By default Splitter ' s behavior be very simplistic:Splitter.on (', '). Split ("Foo,,bar, Quux") This returns a iterable C ontaining ["foo", "" "," Bar "," Quux "]. Notice that "Splitter does not assume" you want empty strings the removed, or that you wish to trim whitespace. If you are want features like this, simply ask for them:
Private Static FinalSplitter my_splitter = Splitter.on (', ')
. Trimresults ()
       . Omitemptystrings ();   Now My_splitter.split ("foo,, Bar, Quux,") returns a iterable containing just ["foo", "Bar", "Quux"]. The order of the "which" configuration methods are called is never significant; For instance, trimming is always applied a before for a checking result, empty of the "order in regardless" t Rimresults () and Omitemptystrings () methods were invoked.                  &N Bsp                          

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.