I am trying to display all the String content from an arraylist, but the size of the arraylist is unknown (using Android Studio) So for example:
fruit = new ArrayList<>() veg = new ArrayList<>()
After some operations, now the story arraylist contained some information, such as:
fruit = {"apple", "orange", "banana", "peach",...};
veg = {"cucumber", "spinach", "pumpkin", "broccoli",...};
I do not know how long the arraylist of fruit and veg are after the operations. But I know that the fruit and veg has the same size of arraylist. I want to store each of the list to be like:
fruitOne = fruit(0), fruitTwo = fruit(1), fruitThree = fruit(2),...
vegOne = veg(0), vegTwo = veg(1), vegThree = veg(2),...
Then I want to display them together as a String? So that I can have a string such as:
String myStore = "I am selling" + fruitOne + " and " + vegOne + "/n" + fruitTwo + " and " + vegTwo + "/n" + fruitThree + " and " + vegThree"...;
I feel like it needs to use For loops to pull each of the list one by one by calling fruit(0), fruit(1),...,fruit(i). But how do I store each of this list of fruit(0), fruit(1),...,fruit(i) independently, so that I can concatenate them together to become one String of myStore?
All the tutorial kept on taking about printLn or logd, so it can print the fruit(i) or veg(i) each for loop, but not really storing the fruit(i) or veg(i) as a variable to be used independently.
Thank you for your help!
String.join(" ", story)? With that, you can keep theArrayListas it is and concatenate its entries.