Empty line at the end of code needs removing

63 Views Asked by At

I have this method that returns a string where a triangle appears on the left size of the diagram, followed by horizontal lines. I used a stringBuilder for this method. The problem is that there is an extra line at the end. I have absolutely no idea where I should put a conditional to prevent it from doing so. Help would be much appreciated. [enter image description here](https://i.stacenter image description herek.imgur.com/WujPw.png)

I have no idea how to fix this. All I want is for that empty line on the end gone.

1

There are 1 best solutions below

0
Algeps On

At the end of the loop, builder.append("\n") is called. One way or another, after each iteration, a new line is added to you. If at the last iteration you no longer need a string, then you can return builder without the last character ("\n").

return builder.substring(0, builder.length() - 1);