gbe
gbe

Reputation: 25

Trim String - get only what I want

I need to trim a given code in Java after the first whitespace. ex. if i have a String (call it inputstartString) with the value

1 100 2 34

I need to get the second number (number 100 in this case) I thought this would go with a trim, but i have absolutely no clue how to do it in this case, afterward I need to do it for the following numbers as well, but I guess once I learn how it goes I can easily do it with the others.

Upvotes: 0

Views: 99

Answers (1)

harpun
harpun

Reputation: 4110

Trim is used to remove trailing or leading whitespace characters. How about String#split()?

String[] elements = "1 2 3 4".split(" ");

This would create an array of 4 elements, each containing a single number.

Upvotes: 1

Related Questions