Common java Methods

Source: Internet
Author: User
Tags date1 string indexof

Zejun. zhou zejun. zhou11 // List listValue = null; // for (int I = 0; I <10; I ++) {// listValue = new ArrayList (); // testEX test = new testEX (); // listValue. add (test. getIi () + "dd" + I); // map. put (test. getIi () + "dd" + I, listValue); //} // for (int I = 0; I <map. size (); I ++) {// List time = new ArrayList (); // List listKey = new ArrayList (); // List listValue1 = new ArrayList (); // Iterator It = map. keySet (). iterator (); // while (it. hasNext () {// String key = it. next (). toString (); // System. out. println (key); // time = (List) map. get (key); // output the context of the ArrayList // for (int k = 0; k <time. size (); k ++) {// System. out. println (map. get (key); // System. out. println (time. get (k); // http: // 172.16.2.123/zentao/user-login-l3plbnrhby82.16.html http://www.jb51.net/books/8602 1. htmlhttp: // www.linuxidc.com/Linux/2011-12/49516p2.htm A, json must package commons-collections-3.2.jar commons-lang-2.3.jar, commons-beanutils-1.7.0.jar, ezmorph-1.0.4.jar commons-logges import these packages try General with these a few can be the commons-beanutils.jar, commons-httpclient.jar, commons-lang.jar, ezmorph. jar, morph-1.0.1.jar map to json Json json = new Json (); // new an object json. setName ("local"); json. setSex ("style"); Json json1 = new Json (); Json1.setName (""); json1.setSex (""); Map list = new HashMap (); list. put ("json", json); list. put ("json1", json1); JSONObject json111 = JSONObject. fromObject (list); // convert to jsonobject JSONObject name1 = json111.getJSONObject ("json"); // obtain jsonobject String names = name1.getString ("name "); // convert the value String from jsonobject to jsonobject string str = "{'string': 'json', 'integer': 1, 'double': 2, 'boolean ': true} "; JSONObject jso NObject1 = (JSONObject) JSONSerializer. toJSON (str); // jsonobject and jsonarray use JSONObject jsonObject = new JSONObject (); // jsonobject and jsonarray use JSONObject jsonObject1 = new JSONObject (); jsonObject1.element ("name", "1"); JSONArray jsonArray = new JSONArray (); jsonArray. add ("1"); jsonObject1.element ("money", jsonArray); JSONObject jsonObject2 = new JSONObject (); jsonObject2.element ("name", "2 "); JSONArray jsonArray2 = new JSONArray (); jsonArray2.add ("2"); jsonObject2.element ("money", jsonArray2); jsonObject. element ("jsonObject1", jsonObject1); jsonObject. element ("jsonObject2", jsonObject2); JSONObject json1 = jsonObject; JSONObject json2 = json1.getJSONObject ("jsonObject1"); String name = json2.getString ("name "); string sex = json2.getString ("sex"); JSONArray jsonArray1 = json2.getJSONArray ("money" ); String money = (String) jsonArray1.get (0); 2. String. valueOf (int); // convert int to String indexOf () to include.> = 0 otherwise-1 3. Create xml soap. jar import org. apache. soap. util. xml. XMLParserUtils; import org. w3c. dom. document; import org. w3c. dom. element; import javax. xml. parsers. documentBuilder; DocumentBuilder xdb = XMLParserUtils. getXMLDocBuilder (); Document doc = xdb. newDocument (); Element El = doc. createElement ("avresult"); Element rcode = doc. createElement ("retcode"); Element message = doc. createElement ("msg"); rco De. appendChild (doc. createTextNode ("retcode"); message. appendChild (doc. createTextNode ("msg"); El. appendChild (rcode); El. appendChild (message); System. out. println (DOM2Writer. nodeToString (El )); <avresult> <retcode> code </retcode> <msg> csg </msg> </avresult> 4. dom4j-1.6.1.jar parses the xml method in the form of a string Document doc = DocumentHelper. parseText (avResultXml); // convert the string to XML List re = doc. selectNodes ("/avresult/retcode"); Ite Rator I = re. iterator (); while (I. hasNext () {Element ele = (Element) I. next (); String eles = ele. getText (); System. out. println (eles);} Method 2: Document doc = incluenthelper. parseText (avResultXml); // convert the string to XML Element root = doc. getRootElement (); // get the root node Iterator <?> Iter = root. elementIterator ("item"); // obtain the child node item while (iter. hasNext () {Element record = (Element) iter. next (); Iterator <?> Iters = record. elementIterator ("segment"); // obtain the child node segment while (iters. hasNext () {Element records = (Element) iters. next (); // exclude a transit flight String org = records. elementTextTrim ("org") ;}} method 3. Document doc = incluenthelper. parseText (abeXmlResult); root = doc. getRootElement (); // resultBean. setErrorDate (true); String from = root. attributeValue ("From"); 5. cache memcached-2.5.jar 6. dynamic transmission parameter System. out. pr Intln (String. format ("form" + "% s" + "to" + "% s", "fromCity", "toCity ")); form fromCityto toCity 7. Check today's day of the week SimpleDateFormat = new SimpleDateFormat ("yyyy-MM-dd"); // define the date Calendar c = Calendar. getInstance (); // The object created in singleton mode is better than new try {c. setTime (format. parse (""); // parse the time to Wed Jun 19 00:00:00 CST 2013 set the day of the week} catch (ParseException e) {logger.info ("the date to be converted is: "+ pTime); logger.info (" converts a date to the day of the week Error! "+ E. getMessage (); e. printStackTrace ();} int dayForWeek = 0; // defines the number of the day of the week minus 1 to the exact time if (c. get (Calendar. DAY_OF_WEEK) = 1) {dayForWeek = 7;} else {dayForWeek = c. get (Calendar. DAY_OF_WEEK)-1;} return String. valueOf (dayForWeek); // converts int to String} 8. baseCabins = baseCabinList. toArray (new Basecabin [0]); // The set is converted to an array bawcs = new BAirwayCw [listBAirwayCws. size ()]; 9. // get the difference between 12.00 and the current time SimpleDateForm At simple = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss"); // defines the input format String time = simple. format (new Date (); // the corresponding time 2013-06-19 // 14:58:03 System. out. println (time); Calendar currentDate = Calendar. getInstance (); // defines the time object currentDate. set (Calendar. HOUR_OF_DAY, 23); // hour currentDate. set (Calendar. MINUTE, 59); // MINUTE currentDate. set (Calendar. SECOND, 59); // SECOND // SimpleDateFormat simple1 = new SimpleDateFormat ("y Yyy-MM-dd // HH: mm: ss "); String endtime = simple. format (Date) currentDate. getTime (). clone (); System. out. println (endtime); // 2013-06-19 23:59:59 // SimpleDateFormat inputtime = new SimpleDateFormat ("yyyy-MM-dd // HH: mm: ss"); try {Date date = simple. parse (time); long times = date. getTime (); Date date1 = simple. parse (endtime); long times1 = date1.getTime (); long ss = (times1-times)/1000; // second System. out. println (Ss/60); // System. out. println (ss/3600); // hour System. out. println (ss);} catch (ParseException e) {// TODO Auto-generated catch block e. printStackTrace ();} 10. The current time is long st = System. currentTimeMillis (); 11. if (tax = null) {continue;} 12. Comparison time: SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd "); // format: Date date1 = sdf. parse ("2013-01-05"); // convert it to date Date date2 = sdf. parse (""); // convert Date if (date1.getTime ()-date2.getTime ()> 0) // convert it to long 13, effectively determine to exit if (fail = true) {return variable} connectingFlight: // an item of a transit flight represents a route. If there are multiple segments in the item, it indicates that the link will be continue connectingFlight. 14. Read the configuration parsing xml. <? Xml version = '1. 0' encoding = 'utf-8'?> <Items> <item name = 'beijing'> PEK, NAY </item> <item name = 'shanghai'> SHA, PVG </item> <item name = 'Xi 'AN '> XIY, SIA </item> </items> "; String file = Class name. class. getResource ("/multi-city.xml "). getFile (); Document config = incluenthelper. parseText (FileUtils. readFileToString (new File (file), "UTF-8"); List <Element> items = doc. selectNodes ("// items/item"); String cts; List <String> cityList; for (Element item: items) {cts = item. getText Trim (); cityList = Arrays. asList (cts. toUpperCase (). split (",") ;}}15. string to list set List list = Arrays. asList ("sd, f ". toUpperCase (). split (","). In linux, you cannot find the configuration file path. Sixteen, not equal to null, not equal to null StringUtils. isNotBlank (Stinng) 17. // set proxy ----- start ----- String strProxy = "172.16.1.35"; String strPort = "80"; Properties systemProperties = System. getProperties (); systemProperties. setProperty ("http. proxyHost ", strProxy); sys TemProperties. setProperty ("http. proxyPort ", strPort ); // set proxy ----- end ----- bean clone and copy // create two objects for replication. When the first object is copied to the second object, only the same BeanCopier copy = BeanCopier is copied. create (CompsInfo. class, QueryHkgsOutput. class, false); for (int I = 0; I

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.