Suppose you have an arraylist of 10 indexes including either the numbers 1, 2, or 3 only. I am trying to get these to print without repeating the same number consecutively if possible.
For example, arraylist includes the numbers {1,1,1,2,1,2,2,3,1,2}
I would like it to print as: {1,2,3,1,2,1,2,1,2,1}
Sorry if this can be done much simpler than what I am trying to do. I am still pretty new to programming.
int j;
int k;
for (j=0; j<p.size()-1;j++)
{
for(k =1; k<p.size()-1;k++)
{
if(p.get(k)==p.get(j))
{
// Person temp = p.get(j);
// p.remove(j);
// p.add(temp);
}
}
}
Not just that.. Try this: