I have got a little problem with printing out comma in my java project. In forEach
section the program is always printing out "," > even after the last word... see output
.listener("lookAround", (Game g, String action, AbstractGameObject object, Object retVal) -> {
System.out.print("You see: \n\t");
if (g.getItemsInRoom((Room) object).isEmpty() && g.getDoorsInRoom((Room) object).isEmpty())
System.out.print("nothing");
g.getItemsInRoom((Room) object)
.stream()
.forEach(item -> System.out.print(item.getName() + ", "));
g.getDoorsInRoom((Room) object)
.stream()
.forEach(door -> System.out.print(door.getName() + ", "));
System.out.println("\n");
})
The output:
You see:
Black Wooden door, Brown Wooden door,
I would like output:
You see:
Black Wooden door, Brown Wooden door
Is there a easy way to solve this problem ?
Thank you for a help :)
No comments:
Post a Comment