Talking about the tool class _java of common string and collection class conversion

Source: Internet
Author: User

In projects, we often need to convert the received string to the corresponding collection class to save, or to convert the collection class to a string for easy transmission, which encapsulates several common methods that are convenient for this conversion requirement.

Import Java.util.Arrays;
Import java.util.Collection;
Import Java.util.HashMap;
Import Java.util.HashSet;
Import Java.util.Map;
Import java.util.Properties;
Import Java.util.Set;

Import Java.util.TreeSet; public class Mystringutils {/** * Converts a string to a set collection class * separator is any whitespace character/public static set<string> Parseparame
    Terlist (String values) {set<string> result = new treeset<string> ();
      If values!= null && values.trim (). Length () > 0) {//The spec says the scope is separated by spaces
    string[] tokens = Values.split ("[\\s+]");//matches any whitespace character result.addall (arrays.aslist (tokens));
  return result;  /** * Converts the collection to a specified form of String */public static string Formatparameterlist (collection<string> value) {return Value = null? Null:StringUtils.collectionToDelimitedString (Value, ",");//Specify Delimiter}/** * Extract the required key value from query string to deposit in map * Query form Name=god&password=111&method=up * * public static Map<striNg, string> extractmap (String query) {map<string, string> Map = new hashmap<string, string> (); Properties Properties = Stringutils.splitarrayelementsintoproperties (stringutils.delimitedlisttostringarray) (query
    , "&"), "="); if (properties!= null) {for (Object Key:properties.keySet ()) {Map.put (key.tostring (), Properties.get (ke
      y). toString ());
  } return map;
    /** * Compare two sets for equality */public static Boolean Containsall (set<string> target, set<string> members) {
    target = new hashset<string> (target);
  Target.retainall (members)//Take two sets of intersection return target.size () = = Members.size (); }
}

The above this article discusses the common string and the collection class conversion tool class is small series to share to everybody's content, hoped can give everybody a reference, also hoped that everybody supports the cloud habitat community.

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.