0

I got a problem in String type that :

String from list-String is not the same as original String

Here are my sample codes

    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");

and then put the map to another method

  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");
    }

Why do I always get an result like this : 01 true 02 true 03 fail 04 fail

It's all okay for a long while. errors appeared recently.

but I didn't change anything.

The code is used in Java 1.6 64bit - Eclipse

Text file Encoding : UTF-8

I have been tried for a long while. Best regards for anyone who gives a hand.

AmerDwight
  • 13
  • 3

3 Answers3

0

There is a special character in "1829690014". Just re-type the input strings (specially 1) in parameters_test and it should work fine.

Jaydip Rakholiya
  • 792
  • 10
  • 20
0

Your String "1829690014" in list is [‭, 1, 8, 2, 9, 6, 9, 0, 0, 1, 4] and not [‭1, 8, 2, 9, 6, 9, 0, 0, 1, 4] so when you are comparing these two, it is giving error.

Pooja Aggarwal
  • 1,163
  • 6
  • 14
  • Thanks for your reply. But I had announced List ,should't it be like this "{3=[16], 2=[1829690014], 1=[BXJ006], 0=[WM188126M]}" ? – AmerDwight Sep 19 '18 at 08:27
  • List would be like this only but when you debug and see the value of string you will find your string in the way I have mentioned. – Pooja Aggarwal Sep 20 '18 at 03:13
0
  • The Text file contains some special characters and encoding is not properly set to UTF-8.
  • re-type below line.

parameters_test.put("2", new LinkedList());
parameters_test.get("2").add("1829690014");

Ajinkya
  • 79
  • 1
  • 6
  • Well...Sir ,I had simply compared our codes and then only replaced the "createdMap" ,and it actually work . but i don't know how. can we share some opinion? – AmerDwight Sep 19 '18 at 08:22
  • By default ISO 8859-1 character encoding is used for Eclipse properties file, so if the file contains any character beyond ISO 8859-1 then it will not be processed as expected. please have a look here - https://stackoverflow.com/questions/31143923/eclipse-wrong-java-properties-utf-8-encoding/31144165 – Ajinkya Sep 26 '18 at 12:17