Comparação de Strings (Iguais) em matriz e array não entram em condição IF

Pessoal! Help!
Estou desenvolvendo uma aplicação desktop (que deveria ser fácil kkkk) que trabalha com 3 matrizes globais, 2 dessas matrizes são carregadas a partir de arquivos texto e xml para formar uma 3° matriz que irei utilizar num Jtable. O que acontece é que quando faço a comparação de Strings armazenadas e elas sendo iguais, nunca entra na condição If. Já tentei com ==, .equals, já criei variaveis para receber os parâmetros e nada. Já depurei todo o códido e as variáveis recebem as Strings iguais mas nunca entram no IF para concatenar e salvar na 3° matriz. Ja pesquisei aqui no forum e até achei assuntos relacionados, mas aplicando no código não funciona. Sou novato no assunto e não trabalho com programação, então tenham paciência comigo kkkk.
Criei uma classe Item conforme codigo abaixo + construtor + getters e setrs

public class Item {

    private String codigo;
    private String workCenter;
    private String controlKey;
    private String orderQtt;
    private String maxPackage;

    public Item() {

    }

A matriz XML é formada por 2 colunas codigo e qtd
Cod | qtd
xx12312 | 23
xx32112 | 200
xx32321 | 100

A matriz Base é formada por 4 colunas (a base é ~20k linhas fixas)
Cod | WorkCenter | ControlKey | MaxPackage
xx32112 | PR2907OM | AF33 | 22

A 3° é a matrizTable que irá concatenar os dados da matriz base a partir das linhas da matrizXML comparando os códigos. Deveria ficar nesse formato:
Cod | WorkCenter | ControlKey | Qtd | MaxPackage
xx32112 | PR2907OM | AF33 | 200 | 22

O código que comparo as Strings de item.codigo estão em uma classe MatrizTable
o problema está nos ifs no metodo createMatrizTable

public class MatrizTable {

    public static void add(String codigo, String workCenter, String controlKey, String orderQtt, String qtdMaxPackage) {
        //array de 4 posições salvo dentro do array global - array da base de dados txt
        ArrayList<String> l = new ArrayList<>();
        l.add(codigo);
        l.add(workCenter);
        l.add(controlKey);
        l.add(orderQtt);
        l.add(qtdMaxPackage);

    Global.matrizTable.add(l);

    //System.out.println(Global.matrizBase.get(3).get(0));
}

public static void delete(String item) {
    for (int i = 0; i < Global.matrizTable.size(); i++) {
        if (Global.matrizTable.get(i).get(0).equals(item)) {
            Global.matrizTable.remove(i);
            System.out.println("Item a ser removido foi encontrado " + Global.matrizTable.get(i).get(1) + "= item: " + item);
        }
        //System.out.println();
    }
}

public static void imprime() {

    //System.out.println(Global.matrizBase.get(100));
    System.out.println("\n\nMatrizTable");
    //print the 2D ArrayList or nested ArrayList
    for (int i = 0; i < Global.matrizTable.size(); i++) {
        for (int j = 0; j < Global.matrizTable.get(i).size(); j++) {
            System.out.print(Global.matrizTable.get(i).get(j) + "|");
        }
        System.out.println();
    }

    //System.out.print("\n\n" + Global.matrizTable.get(0).get(0) + "|" + Global.matrizTable.get(0).get(1) + "|" + Global.matrizTable.get(0).get(2) + "|" + Global.matrizTable.get(0).get(3) + "|" + Global.matrizTable.get(0).get(4));
}

public static void clean() {
    for (int i = 0; i < Global.matrizTable.size(); i++) {
        Global.matrizTable.remove(i);
    }
    System.out.println();
}

public static void createMatrizTable() {//concat matrizXML with matrizBase to complite the list
    Item item = new Item();
    String var;
    String var2;

    //read line by line, matrizXML is the reference to create matrizTable because we need to report it
    for (String[] matrizXML : Global.matrizXML) {
        if (matrizXML[0] != null) {
            //System.out.println(matrizXML[0] + "|" + matrizXML[1]);

            item.setCodigo(matrizXML[0]);
            item.setOrderQtt(matrizXML[1]);

            MatrizTable.add(item.getCodigo(), "", "", item.getOrderQtt(), "");
            //System.out.println("---> " + item.getCodigo() + " " + item.getOrderQtt());
            //search in matrizBase item that was found != null position and add values to class item to complete the matrizTable
            for (int i = 0; i < Global.matrizBase.size(); i++) {

                var = Global.matrizBase.get(i).get(0);
                var2 = item.getCodigo();

                //---------Deveria entrar aqui em um dos ifs mas pula todos --------------------
                if (Global.matrizBase.get(i).get(0).equals(item.getCodigo())) {
                    System.out.println("deu certo com: if (Global.matrizBase.get(i).get(0).equals(item.getCodigo()))");
                }

                if (var == var2) {
                    System.out.println("deu certo com: if (var==var2)");
                }

                if (var.equals(var2)) {
                    System.out.println("deu certo com: if(var.equals(var2))");
                }
                if (var.equalsIgnoreCase(var2)) {
                    System.out.println("deu certo com: if (var.equalsIgnoreCase(var2))");
                }
                if (new String(var).equals(new String(var2))) {
                    System.out.println("deu certo com: if (new String(var).equals(new String(var2)))");
                }
                if (var.hashCode() == var2.hashCode()) {
                    System.out.println("deu certo com: if (var.hashCode()==var2.hashCode())");
                }

                if (var.matches(var2)) {
                    System.out.println("deu certo com: if (var.matches(var2))");
                }

                if (var.startsWith(var2)) {
                    System.out.println("deu certo com: if (var.startsWith(var2))");
                }
                if (var.toUpperCase().equals(var2.toUpperCase())) {
                    System.out.println("deu certo com: if (var.toUpperCase().equals(var2.toUpperCase()))");
                }

                if (var == var2) {
                    System.out.println("deu certo com: if (var == var2)");
                    item.setWorkCenter(Global.matrizBase.get(i).get(1));
                    item.setControlKey(Global.matrizBase.get(i).get(2));
                    item.setMaxPackage(Global.matrizBase.get(i).get(3));
                    //System.out.println(item.getCodigo() + " " + item.getWorkCenter() + " " + item.getControlKey() + " " + item.getOrderQtt() + " " + item.getMaxPackage());
                }
            }
        }
    }
    //MatrizTable.imprime();

}
}

A comparação de Strings é com equals pelo que isto deverá funcionar

if (var.equals(var2)) {
    System.out.println("deu certo com: if(var.equals(var2))");
}

Ou isto, se quiseres ignorar diferenças de maiusculas e minusculas

if (var.equalsIgnoreCase(var2)) {
    System.out.println("deu certo com: if (var.equalsIgnoreCase(var2))");
}

O estranho é que não entra em nenhum desses ifs. No depurador as variáveis aparecem, mas não consigo que a comparação seja executada corretamente, é como se não tivesse nada por baixo dessa variavel… Já fiz várias adaptações no código e nada. Não consigo descobrir o problema.

O que está na classe Global?
Fiz um teste com

static List<List<String>> matrizTable = new ArrayList<>();
static List<List<String>> matrizBase = Arrays.asList(Arrays.asList("xx32112", "PR2907OM", "AF33", "22"));
static String[][] matrizXML= {{"xx12312", "23"}, {"xx32112","200"}, {"xx32321", "100"}};

e funcionou

deu certo com: if (Global.matrizBase.get(i).get(0).equals(item.getCodigo()))
deu certo com: if (var==var2)
deu certo com: if(var.equals(var2))
deu certo com: if (var.equalsIgnoreCase(var2))
deu certo com: if (new String(var).equals(new String(var2)))
deu certo com: if (var.hashCode()==var2.hashCode())
deu certo com: if (var.matches(var2))
deu certo com: if (var.startsWith(var2))
deu certo com: if (var.toUpperCase().equals(var2.toUpperCase()))
deu certo com: if (var == var2)

Atenção que este caso só funciona porque as Strings estão hardcoded e assim consegue avaliar que é a mesma String (procura por “java string pool” se quiseres mas detalhes). Se forem valores lidos de algo externo (base de dados, ficheiro, console) já não funciona. Todos os restantes funcionarão na mesma.

Só pode ser isso, pois os valores são extraidos de arquivo xml. Vou ter que repensar o meu código.

Não precisas de repensar. A frase é válida para comparação de Strings com ==
Com equals (como deve sempre ser feito) funciona para qualquer caso.

Descobri o problema pmlm. Ler arquivo xml como se fosse um txt não é uma boa ideia,Tive que converter o arquivo xml para string (DOMSource) antes de comparar as variáveis, utilizei o código abaixo para converter e salvar em um arquivo temporário.

//xml to string
         String st = null;

        try {
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            InputSource is = new InputSource(ManipulaArqConfig.xmlPath + jobComp);
            //System.out.println(ManipulaArqConfig.xmlPath + jobComp);

            org.w3c.dom.Document document = docBuilderFactory.newDocumentBuilder().parse(is);

            StringWriter sw = new StringWriter();
            
            Transformer serializer = TransformerFactory.newInstance().newTransformer();
            serializer.transform(new DOMSource(document), new StreamResult(sw));

            st = sw.toString();

        } catch (ParserConfigurationException | SAXException | IOException | TransformerException e) {
            //System.out.println("\nErro ao tentar ler arquivo XML");
            JOptionPane.showMessageDialog(null, "JOB Não encontrado!");
        }

Não sei se tinha outra forma mas essa funcionou em praticamente todos os ifs. Problema resolvido e obrigado pela contribuição, dicas são sempre bem vindas :nerd_face: