How can I safely remove the front and back gaps in Java?

Asked 1 years ago, Updated 1 years ago, 90 views

For example, "Hello. Good morning. " If there's a string like that, I want to say, "Hello, good morning." But I want to make a regular meal that solves this problem I wonder if the method is supported.

java space

2022-09-22 22:18

1 Answers

You can use the method called trim in Java's String class.

String tmp="Hello. Good morning.    " ;
tmp = tmp.trim();
System.out.println(tmp);

If you do it like this, Output result Hello. Good morning.

This is how it's printed.


2022-09-22 22:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.