我有一个问题,我认为这是一个字符与一些比较。
String FindCountry = "BB";
Map Cont = new HashMap <> ();
Cont.put("BA-BE", "Angola");
Cont.put("9X-92", "Trinidad & Tobago");
for ( String key : Cont.keySet()) {
if (key.charAt(0) == FindCountry.charAt(0) && FindCountry.charAt(1) >= key.charAt(1) && FindCountry.charAt(1) <= key.charAt(4)) {
System.out.println("Country: "+ Cont.get(key));
}
}
在这种情况下,代码打印“安哥拉”,但如果
String FindCountry = "9Z"
它不显示任何信息。我不知道我想的问题是,它不能比较是“2”比“Z”更大。在这个例子中,我只有两个Cont.put(),但在我的文件,我得到了更多和他们中的很多,不仅有字符。我有一个问题他们。
什么是与一些比较字符的最聪明的和最好的方式是什么?其实,如果我定了一个规矩,如“1”比“Z”一切都会好的,因为我需要更大的这样更大:A-Z-9-0。
谢谢!