Java Web Utility Tip 02

Source: Internet
Author: User

Date Time conversion to page display
    两种方式:    1. OutputStream out = response.getOutputStream(); map.put("enterFromTime", sdf.format(itemData.getEnterFromTime()));// 入单时间    2. map.put("changeTime", DateUtil.formatDate(itemData.getChangeTime()));// 转单时间    第2种好。
date plus Day

Advanced search will use the end date to add one day to get the matching search results

    //date plus one day:    //End time    if(Searchjson.Has ("EndTime")){StringEndTime=(String) Searchjson.Get"EndTime");if(!EndTime.equals("")){Date Date =Dateutil.GetDateFormat ().Parse (endTime); Calendar Cal=Calendar.GetInstance (); Aa..SetTime (Date); Aa..Add (Calendar.DATE,1);Date =Aa..GetTime (); Itemsearchwrap.Setendtime (Date); }    }
examples of String,integer to BigDecimal in Java

Example 1,string turn BigDecimal

publicclass Test{     publicstaticvoidmain(String[] arg) {         String str1="2.30";        BigDecimal bd=new BigDecimal(str1);        System.out.println(bd);    } }

Direct new is on the line.

Example 2,bigdecimal and String conversions

/* Method of constructing BigDecimal by numeric String * method of setting BigDecimal number of decimal digits */ ImportJava.Math.BigDecimal;//numeric stringStringStrbd="1048576.1024";//Construct variable BD of type BigDecimal with string content as valueBigDecimal BD=NewBigDecimal (STRBD);//Set the number of decimal digits, the first variable is the number of decimal digits, the second is the trade-off method (rounding)Bd=Bd.Setscale (2, BigDecimal.ROUND_HALF_UP);//Convert to string outputStringOutstring=Bd.ToString ();

Add: Integer Turn BigDecimal

BigDecimal(Integer.parseInt(findCcid.toString()))
type conversion string,list,int in Java

1.String->list

String[] arr = tpAssignMarkStr.split(",");        List<StringArrays.asList(arr);

2.list->string

list<String> marklist = Tpassignmarkfielddao.gettpassigndeptmarkfield (NULL, Paperid);StringMarkstr = Stringutils.join (Marklist,",");//Take into account the storage of multiple flags        String[] markstring = Markstr.split (",");        list<tpsampledatabean> dataList = Tssampletemplatebean.gettpsampledatabeans (); list<String> sampledataids=Newarraylist<String> ();//Data list for storing samples         for(Tpsampledatabean d:datalist) { for(Stringstr:markstring) {if(Str.equals (D.getfieldchar1 ())) {//FIELDCHAR1 is a sign                    if(Stringutils.equals (D.getpaperid (), Paperid) && stringutils.equals (D.getcomplianceid (),                    Complianceid)) {Sampledataids.add (D.getid ()); }                }            }        }

1.int->string

int i=12345;String s="";第一种方法:s=i+"";第二种方法:s=String.valueOf(i);第三种方法:StringInteger.toString(i);

2.string->int

s="12345";int i;第一种方法:i=Integer.parseInt(s);第二种方法:i=Integer.valueOf(s).intValue();

PS1:

The first method: s=i+ ""; Produces two String objects the second method: S=string.valueof (i);
Use static methods of the string class directly, producing only one object
The first method: I=integer.parseint (s);//Use static methods directly, do not produce extra objects, but throw exceptions
The second method: I=integer.valueof (s). Intvalue ();//integer.valueof (s) is the equivalent of new
Integer (Integer.parseint (s)), also throws an exception, but produces more than one object

PS2:

Double, Float, and Long turn into strings in a similar way.

Java Web Utility Tip 02

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.