ArrayList () prints true when traversing it

1

I have the following function that generates a ArrayList but at the moment of traversing it, it returns true. How can I see the content?

    public static ArrayList ordenaNodos(ArrayList nodeList){

    ArrayList cfdiList = new ArrayList();
    //recorre lista de nodos
    String cfdi = "";
    for(int i=0; i<nodeList.size(); i++){
       cfdi += nodeList.get(i).toString();
       if(nodeList.get(i).toString().equals("</cfdi:Comprobante>")){
           cfdiList.add(new ArrayList().add(cfdi));
           cfdi = "";
       }
    }

    return cfdiList;
}
    
asked by Nov Esk Eduard 09.06.2017 в 18:49
source

2 answers

0

Firstly, when you add an element to ArrayList , you are actually adding another ArrayList , you only need to save the value within ArrayList cfdiList :

   //cfdiList.add(new ArrayList().add(cfdi));
    cfdiList.add(cfdi);

To print the result of the method:

for(int i=0; i< resultadoOrdenaNodos.size(); i++){    
    System.out.println("Elemento" + i + " , valor: " +  resultadoOrdenaNodos.get(i));
 }
    
answered by 09.06.2017 / 19:50
source
0

With this you should return what you want:

ArrayList cfdiList = new ArrayList(); 
String cfdi = "";
for(int i=0; i<nodeList.size(); i++){   //  Iteras la nodeList
    cfdi = nodeList.get(i).toString();  //  Obtienes el valor String del ojeto en el índice "i". No usar "+"
    //  Como ya tienes el valor en ese índice no vuelves a usar los metodos, simplemente comparas la variable "cfdi"
    if (cfdi.equals("</cfdi:Comprobante>")){
       cfdiList.add(cfdi);
    }
}

I hope you serve, greetings.

    
answered by 09.06.2017 в 20:20