dimanche 8 mars 2015

Why doesn't it put the element on a string of a new list ?


Vote count:

0




I have a list of list of strings, and I want to get some strings from it to store them in a new list of list of strings. Here's the code:



List<List<String>> colectieTotala = new ArrayList<>();
List<List<String>> dePusInRaport = new ArrayList<>();
List<String> listaPentruTest = new ArrayList<>();
int i = 0;

dePusInRaport.add(listaPentruTest);

for (int y = 0; y < colectieTotala.size(); y++)
{
String categorie;
String categorieCurenta = "";
char spatiu = ' ';
int h = 0;
List<String> toateCategoriileCurente = new ArrayList<>();
colectieTotala.get(y).get(0);
categorie = colectieTotala.get(y).get(1);
colectieTotala.get(y).get(4);

if (categorie.contains(" "))
{
for (int k = 0; k < categorie.length(); k++)
{
for (int p = 0; p < dePusInRaport.size(); p++)
{
if ((categorie.charAt(k)) == spatiu)
{
categorieCurenta = categorie.substring(h, k);
h = k+1;
dePusInRaport.get(p).add(categorieCurenta);
}

if (k == categorie.lastIndexOf(spatiu))
{
categorieCurenta = categorie.substring(k+1, categorie.length());
dePusInRaport.get(p).add(categorieCurenta);

}


}
}

}

}
System.out.println("dePusInRaport -> " + dePusInRaport);


The problem is that this code adds the strings from colectieTotala only on the first list of strings from from dePusInRaport, and what I want is getting the strings from colectieTotala and store them, each on a new List of Strings, of dePusInRaport. If you need further information, please ask for it. I'm not that good at explaining.


So, what System.out.println("dePusInRaport -> " + dePusInRaport); prints in the end is this:



[[Drama, Mystery, Crime, Drama, Mystery, SF, Drama, SF, Psihologic]]



but I want something like this:



[[Drama] [Mystery] [Crime] [Drama] [Mystery] [SF] [Drama] [SF] [Psihologic]]



I think there's a bad for in there, either I just forgot to add one...



asked 35 secs ago







Why doesn't it put the element on a string of a new list ?

Aucun commentaire:

Enregistrer un commentaire