How to join two Arrays?

0

Hello, I have the following problem I have an ArrayList that returns several small arrays of two positions

String[] temp = new String[2];

and has the arrayList that saves adds several "temp";

ArrayList lista = new ArrayList();
while(rs.next()){
   if(rs.getString("texto") != null){
    temp[0] = String.valueOf(rs.getInt("id"));
    temp[1] = rs.getString("texto");
    lista.add(temp);
   }else{
    temp[0] = String.valueOf(rs.getInt("id"));
    temp[1] = rs.getString("valor");
   }
}

Good temp[0] contains the ID of a table my challenge and get the values from the ArrayList and group them by means of the ID position, so there would be only some arrays of type array tempx[] contain all temp[1] which has temp[0] with the same value. Which then goes to another Array List

Type something like this

enquanto lista.get(a).temp[0] conter o mesmo identificador faça
tempx[i] = lista.get(i).temp[1]
i++;
Quando o lista.get(a).temp[0] mudar então  um novo arrayList deve receber essa nova array.
listaAtualizada.add(tempx);

I'm not very good at ideas today and I'm suffering to do that.

    
asked by anonymous 17.05.2016 / 16:47

1 answer

0

List tempA = new ArrayList(); for(Object l: lista){ String[] arrayA = new String[2]; String[] ArrayB = (String[]) l; int cont = 0; for(Object l2: lista){ String[] tw = (String[]) l2; if(ArrayB[0].equalsIgnoreCase(tw[0])){ tempA.add(tw[1]); } } tempX.add(tempA); tempA = new ArrayList(); } This generates many duplicate elements so I remove them using // adiciona todos os elementos incluindos duplicadas Set<String> hs = new HashSet<>(); hs.addAll(tempX); tempX.clear(); tempX.addAll(hs);

    
17.05.2016 / 19:11