ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

String类比较日期

2019-05-28 23:37:47  阅读:294  来源: 互联网

标签:String argument value 比较 日期 &# lexicographically string


int java.lang.String.compareTo(String anotherString) Compares two strings lexicographically(字典序; 按字典顺序;).

The comparison is based on the Unicode value of each character in the strings.

The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string.

The result is a negative integer if this String object lexicographically precedes (在…之前发生)the argument string.

The result is a positive integer if this String object lexicographically follows the argument string.

The result is zero if the strings are equal; compareTo returns 0 exactly when the equals(Object) method would return true.

 

 

This is the definition of lexicographic ordering.

If two strings are different, then either they have different characters at some index that is a valid (有效的) index for both strings, or their lengths are different, or both.

 

(1) 第一种情况

 

If they have different characters at one or more index positions, let k be the smallest such index;

then the string whose character at position k has the smaller value, as determined by using the < operator, lexicographically precedes the other string.

In this case, compareTo returns the difference of the two character values at position k in the two string -- that is, the value:

this.charAt(k)-anotherString.charAt(k)

 

(2)第二种情况

If there is no index position at which they differ, then the shorter string lexicographically precedes the longer string.

In this case, compareTo returns the difference of the lengths of the strings -- that is, the value:

this.length()-anotherString.length()

 

参数: anotherString the String to be compared.

 

Returns:

the value 0 if the argument string is equal to this string;

a value less than 0 if this string is lexicographically less than the string argument;

and a value greater than 0 if this string is lexicographically greater than the string argument.

 

数字 转 Unicode编码对照:

0123456789

&#48;&#49;&#50;&#51;&#52;&#53;&#54;&#55;&#56;&#57;

 

标签:String,argument,value,比较,日期,&#,lexicographically,string
来源: https://www.cnblogs.com/duyufei/p/10941138.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有