I have this program reads a file made up with words line by line into my Arraylist, then I want to print this ArrayList on to my console also line by line, however, I can only manage to print 1 word from that list (you can understand why from my code below). I would appreciate all kinds of input.
*Note1: I have tested both my reader method and my ArrayList they seem to work well, I can see all the elements that are added into my ArrayList.
*Note2: I could just print out with print-stream however I can't change the method signature, thus I have to return String with this method and I could not find any way to print the whole list on to my console.
*Edit: To clarify I do not want to print the list, I want this method to pass the String (as a list with all the elements) to another class's method that puts this String I returned from this method on to text box I created with GUI. Therefore I need this method to "return String(arStr)" somehow but I could not figure out yet.
public static String toStringFromArrayList(ArrayList<String> arStr) {
String result = null;
for (String s : arStr) {
result = s;
}
return result;
}
** This is what I meant to do if anyone needs a similar solution can check it below **
public static String toStringFromArrayList (ArrayList<String> arStr) {
String result ="";
for (String s: arStr) {
result += s+"\n";
}
return result;
toString()for aString.System.out.println(arStr);. This will print the entire list on one line, though.return arStr.toString();the right thing? Or ratherreturn String.join("\n", arStr);? We can't know what you want.