Simple use of the strings class-code elegant Way Guava (i)

Source: Internet
Author: User

Objective

In front of the Guava class library has been briefly introduced (blog: Java Code elegant Way-guava (with the relevant jar package download)), the following is a brief introduction of a strings tool class use, learn the flexible use of strings tools, will use our development, more time and effort, Code robustness and readability, and more concise, this is what I call "code elegance", let us develop in the time to deal with more important things, nonsense not to say, a look at the code is all clear.

Common functions and use of the strings class
/** * Guava Strings tool class use, null and empty judgment and conversion * @author chenleixing */public void Teststrings () {Strings.isnullorempty ("") ;//return Truestrings.nulltoempty (NULL);//"Strings.nulltoempty" ("Chen");//Return "Chen" Strings.emptytonull ("");// Return Nullstrings.emptytonull ("Chen");//Return "Chen" Strings.commonprefix ("Aaab", "AAC");//"AA" otherwise return "" Strings.commonsuffix ("AAAC", "AAC");//"AAC" otherwise returns ""}

The strings class also has a method to get the same prefix and suffix of 2 strings: Commonprefix,commonsuffix, and repeatedly increments a string to a certain length at the beginning or end of a string: Padend and Padstart methods, This is no longer an introduction because of the reasons below.

Yes, perhaps you will think of the Apache Common-lang package in the StringUtils, this tool analogy guava strings powerful, guava some of these methods, StringUtils class have, And there are many other ways to deal with strings, see my blog post Commons-lang common methods ,the StringUtils method of the complete introduction. In this introduction strings mainly let everybody understand guava also have some corresponding function, moreover guava's super function is far from this, the back of the time period I will detail. It is recommended that you develop a similar function or use the StringUtils tool class, after all, this tool is much more powerful.

Simple use of the strings class-code elegant Way Guava (i)

Related Article

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.