Buzz Code
Published in

Buzz Code

Java 8 | StringTokenizer Practice

Hi guys! Welcome to another day of practicing Java with me. Like I said on the last post, I brought some practice questions of StringTokenizer, so if you miss the last posts check them out before!

[Question 1] Split the String “sample” with delimiters “#”, “/” and includes delimiters into tokens.

String sample = "A#whole/new#/World";

It’s a same kind of the question we’ve already done, but here I put two signs at the second parameter. It means there are two delimiters and I put true at the end so it will includes delimiters into tokens.

[Question 2] How many word “big” in the String “sample”?

String sample = "A big black bug bit a big black bear, made the big black bear bleed blood.";

This time, I declared the int cnt to count how many word “big” in the sample String. Obviously there are Strings in the tokens so I used the equals() method to compare both Strings.

[Question 3] Cha-ching!

String sample has some good information of stocks, it has “company name/value” and each of the information is divided with the “@”. Store them in the array, and print all of them out like the result ex) below.

String sample = "Samsing/95000@Lz/52000@BuzzCode/999999";result ex) -> Company name : Samsing, Value : 95000

There are many ways to do it, but I used the Two dimensional array here. So we don’t forget how to use it haha! As you see when I declare the array I put
st.countTokens()/2 as the length of its column, in case there are more stock information added in the sample String.

So at the end there will be the information like this in the array!

That all for today guys! Let’s solve some more practice on next time! Thank you for reading my post! See ya!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store