Skip to content
Advertisement

How to return arraylist vertically

I am trying to return an array list vertically but I’m having some issues trying to implement it. Below is my code, and the return results; Output is what I’m trying to get to be vertically

JavaScript

}

JavaScript

My current output is [2, 4, -1]

I’d like it to be

JavaScript

Any help would be appreciated. Thank you in advance

Advertisement

Answer

Hi if you mean to display each value from results on new line you can do this :

JavaScript

See this code run live at Ideone.com.

JavaScript

Or, use streams to iterate each element of the list, using a method reference to print.

JavaScript

Same result.

Advertisement