字符串比较——compareTo函数
2017-04-07 18:03
155 查看
package com.day03.ifelse; import java.math.BigInteger; /** * @author 王恒 * @datetime 2017年4月7日 下午3:13:50 * @description 字符串比较 */ public class TestCompareTo { public static void main(String[] args) { //单个英文字母的字符串比较 String str = "a"; String str2 = "b"; System.out.println(str.compareTo(str2)+" 单个英文字母"); //多个英文字母的比较 String str3 = "aasf"; String str4 = "gasfd"; System.out.println(str3.compareTo(str4)+" 多个英文字母\n"); //单个的中文的字符串比较 char c1='上'; char c2='海'; //new BigInteger(Integer.toHexString(s),16);//将指定基数的 BigInteger 的字符串表示形式转换为 BigInteger。 System.out.println(new BigInteger(Integer.toHexString(c1),16)+" 上");//19978 System.out.println(new BigInteger(Integer.toHexString(c2),16)+" 海");//28023 String s1 = "上"; String s2 = "海"; System.out.println(s1.compareTo(s2)+" 单个的中文的字符串比较"); //-8045 //多个的中文字符串比较 String s3 = "上战场"; String s4 = "上"; System.out.println("多个中文比较 "+s3.compareTo(s4)+" 多个的中文字符串比较"); } }
相关文章推荐
- 性能测试之字符串比较; C、C++和JAVA
- 第十六周—C语言 (字符串比较—不使用strcat函数)
- 字符串比较的一个问题
- Mybatis if test无效的原因(字符串比较)
- Java字符串比较(equals)
- java中两字符串比较--compareTo方法
- 字符串比较的精妙算法
- 字符串比较——加密术
- object_c字符串比较之:版本号
- [shell基础]——整数比较;字符串比较;文件测试;逻辑测试符
- PHP基础之字符串比较
- object_c字符串比较之:版本号 .
- stringBuffer的使用及字符串比较的区别
- java字符串比较的迷惑(equals,“==”的差异)
- 库函数实现之字符串比较
- mysql 的解决字符串比较的时候区分大小写
- php数字与字符串比较时的注意事项
- js字符串比较的问题
- 字符串比较——最简单的方法(有点水)
- 使用IDE宏遍历代码中的非ASCII字符