为什么它不等于 String 和 String From List<String>
Why does it not equals String and String From List<String>
我在字符串类型中遇到问题:
来自列表字符串的字符串与原始字符串不同
这是我的示例代码
Map<String, List<String>> parameters_test=new HashMap<String, List<String>>();
parameters_test.put("0",new LinkedList<String>());parameters_test.get("0").add("WM188126M");
parameters_test.put("1",new LinkedList<String>());parameters_test.get("1").add("BXJ006");
parameters_test.put("2",new LinkedList<String>());parameters_test.get("2").add("1829690014");
parameters_test.put("3",new LinkedList<String>());parameters_test.get("3").add("16");
然后把map放到另一个方法
if (getParamsMap() != null) {
for (String item : getParamsMap().keySet()) {
List<String> valueList = getParamsMap().get(item);
if (valueList == null || valueList.isEmpty()) {
continue;
}
if (item.equals("0")) {
woCode = valueList.get(0);
} else if (item.equals("1")) {
product = valueList.get(0);
} else if (item.equals("2")) {
purchaseOrder = valueList.get(0);
} else if (item.equals("3")) {
labelNumbers = valueList.get(0);
}
}
}
if(woCode.equals("WM188126M")){
System.out.println("01 true");
}else{
System.out.println("01 fail");
}
if(product.equals("BXJ006")){
System.out.println("02 true");
}else{
System.out.println("02 fail");
}
if(purchaseOrder.equals("1829690014")){
System.out.println("03 true");
}else{
System.out.println("03 fail");
}
if(labelNumbers.equals("16")){
System.out.println("04 true");
}else{
System.out.println("04 fail");
}
为什么我总是得到这样的结果:
01 真
02 真
03 失败
04 失败
好久没事儿了。
最近出现错误。
但我什么都没改。
代码用在Java 1.6 64bit
- Eclipse
文本文件编码:UTF-8
我试了好久了。
向所有伸出援手的人致以最诚挚的问候。
“1829690014”中有一个特殊字符。只需在 parameters_test
中重新键入输入字符串(特别是 1),它应该可以正常工作。
您在列表中的字符串“1829690014”是 [ 1, 8, 2, 9, 6, 9, 0, 0, 1, 4] 而不是 [1, 8, 2, 9, 6, 9, 0, 0, 1, 4] 所以当你比较这两个时,它给出了错误。
- 文本文件包含一些特殊字符,编码未正确设置为 UTF-8。
- 在下面重新输入。
parameters_test.put("2", new LinkedList());
parameters_test.get("2").add("1829690014");
请查看此处的代码 - https://gist.github.com/ajinkya-mundankar/240d0e84dc37ee7ea1b222ed5e697db1。
请参考这里 - Unable to create a file with foreign language characters.
我在字符串类型中遇到问题:
来自列表字符串的字符串与原始字符串不同
这是我的示例代码
Map<String, List<String>> parameters_test=new HashMap<String, List<String>>();
parameters_test.put("0",new LinkedList<String>());parameters_test.get("0").add("WM188126M");
parameters_test.put("1",new LinkedList<String>());parameters_test.get("1").add("BXJ006");
parameters_test.put("2",new LinkedList<String>());parameters_test.get("2").add("1829690014");
parameters_test.put("3",new LinkedList<String>());parameters_test.get("3").add("16");
然后把map放到另一个方法
if (getParamsMap() != null) {
for (String item : getParamsMap().keySet()) {
List<String> valueList = getParamsMap().get(item);
if (valueList == null || valueList.isEmpty()) {
continue;
}
if (item.equals("0")) {
woCode = valueList.get(0);
} else if (item.equals("1")) {
product = valueList.get(0);
} else if (item.equals("2")) {
purchaseOrder = valueList.get(0);
} else if (item.equals("3")) {
labelNumbers = valueList.get(0);
}
}
}
if(woCode.equals("WM188126M")){
System.out.println("01 true");
}else{
System.out.println("01 fail");
}
if(product.equals("BXJ006")){
System.out.println("02 true");
}else{
System.out.println("02 fail");
}
if(purchaseOrder.equals("1829690014")){
System.out.println("03 true");
}else{
System.out.println("03 fail");
}
if(labelNumbers.equals("16")){
System.out.println("04 true");
}else{
System.out.println("04 fail");
}
为什么我总是得到这样的结果: 01 真 02 真 03 失败 04 失败
好久没事儿了。 最近出现错误。
但我什么都没改。
代码用在Java 1.6 64bit
- Eclipse
文本文件编码:UTF-8
我试了好久了。 向所有伸出援手的人致以最诚挚的问候。
“1829690014”中有一个特殊字符。只需在 parameters_test
中重新键入输入字符串(特别是 1),它应该可以正常工作。
您在列表中的字符串“1829690014”是 [ 1, 8, 2, 9, 6, 9, 0, 0, 1, 4] 而不是 [1, 8, 2, 9, 6, 9, 0, 0, 1, 4] 所以当你比较这两个时,它给出了错误。
- 文本文件包含一些特殊字符,编码未正确设置为 UTF-8。
- 在下面重新输入。
parameters_test.put("2", new LinkedList());
parameters_test.get("2").add("1829690014");
请查看此处的代码 - https://gist.github.com/ajinkya-mundankar/240d0e84dc37ee7ea1b222ed5e697db1。
请参考这里 - Unable to create a file with foreign language characters.