按字母顺序比较字符串 [英] Comparing strings by their alphabetical order

查看:100
本文介绍了按字母顺序比较字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

String s1 = "Project";
String s2 = "Sunject";

我想按字母顺序比较上面两个字符串(在本例中为Project) Sunject作为P出现在S之前。
有没有人知道如何用Java做到这一点?

I want to compare the two above string by their alphabetic order (which in this case "Project" then "Sunject" as "P" comes before "S"). Does anyone know how to do that in Java?

推荐答案

String.compareTo 可能是也可能不是你需要的。

String.compareTo might or might not be what you need.

看看这个链接,如果您需要本地化的字符串排序。

Take a look at this link if you need localized ordering of strings.

这篇关于按字母顺序比较字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆