Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to compare the sizes of two strings in java?
How to compare the sizes of two strings in java?
int 1 int2? Long t1= "= result2013101"integer; Simple date format ("

There are three ways to achieve this.

The first method directly uses the compareTo method of string class; t 1; Int yyyyMMdd "result is less than 0; ); & ampparse int(T2); int int 1-int 2; Date and time. nbsp? Sdf simple date format & nbsp; gettime (); Int result sdf attention; Integer: If the result is equal to 0, then t 1 = t2. Pareto (T2); T2; ; Date = d2 = & nbsp; t2 = "d1.gettime ()-d2; =?

The second is to convert this date string into long = & nbsp; parse (t2); ? = & ampnbsp String t2: & nbsp . parse int(t 1); The result? String int new,then t 1 >; Sdf = & ampNbsp, then t 1

The third is to convert the date string into an integer int:result is greater than 0. parse (t1); 20 13 1030 " = & amp; Uninterrupted space

One way of thinking: SimpleDateFormat can be used for processing, and the growth format can be converted, that is, the number of milliseconds from 1970 65438+ 10 month 1 You can directly compare the size. Another way of thinking: Because you use a complete format (written as 07 in July), you can directly use public static void main (string [] _ s) {string str1= "2010-07-1612: 00. long long str 1 = long . value of(str 1 . replace all("[-\ \ s:]"," ")); system . out . println(long str 1); The result is 20100716120000, which is the direct translation growth format.