0

I am trying to compare an String and an array element. If the requested element

package com.company;

public class Main {

    static String[] List = {
            "EUR", "AED"
    };

    static String[] IdList = {
            "EUREUR", "EURAED", "AEDEUR","AEDAED"
    };
    public static void main(String[] args)
    {
        String value1 = "EUR";
        String value2 = "EUR";
        for(int i = 0; i < IdList.length; i++)
        {
            System.out.println(value1+value2 == IdList[i]);
        }
    }
}

The problem is that it always returns false . Even if the requested String matches to a value in the array. Can you help me?

Charles-Eugene Loubao
  • 1,080
  • 2
  • 12
  • 22

1 Answers1

0

You must use String.equals(), not the == operator, to compare strings reliably.

cybersam
  • 63,203
  • 6
  • 53
  • 76