Hi, I want my toString method to print out each item of the arrayList<Integer> w
ID: 3542101 • Letter: H
Question
Hi, I want my toString method to print out each item of the arrayList<Integer> with a for loop but I dont seem to make the right approach. This is what I got:
public String toString(){
String n = "";
for(int i = 0; i<bigNumber.size(); i++){
n = ""+bigNumber.get(i).toString();
}
return n;
}
the bigNumber is a private ArrayList<Integer>, that has been already assigned a value.
I keep getting a wird adress instead of what I want and I know its that way because the value that is assigned during the for loop are local to that forloop or something like that. But this is what most made sense to me. Please help!
Explanation / Answer
public String toString()
{
String n = "";
for(int i = 0; i<bigNumber.size(); i++)
{
// here you have to append all to n
// but every time you are not appending...
// update code below and run your program.
n = n+bigNumber.get(i).toString();
}
return n;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.