Buzz Code
Published in

Buzz Code

Java 8 | String Method 2

Hi y’all! In one of my old post I was talking about three String methods charAt(), equals(), length().

Today I’ll talk about more of the String methods that we can use often. Let’s get this started then!

(1) startsWith()

This method returns true if the String starts with the parameter String, and returns false if it doesn’t.

(2) endsWith()

It returns true if the last letters of the String is same with the parameter String, and returns false if it’s not.

(3) indexOf()

It returns the number of the first index where the parameter letters are. You can put both of String or char in the parameter.

(4) lastIndexOf()

This is basically same with the indexOf() method but it returns the index of the last letter what we looking for.

(5) replace()

It replaces certain letters in the String into the new letters and returns changed String. It has two parameters, it changes the first parameter into the second one. This method doesn’t affect to the original String.

(6) split()

It can divide the String with the certain letter, and returns array that has divided Strings in each indexes. The array doesn’t contain the letter that divides the String.

(7) subString()

This method returns String in the certain range of the index, so it needs int type parameters which set the range of the index. If you put just one number as a parameter, it returns the String starts from that index to the end. and if you put two numbers as parameters, it returns the String starts from the first parameter to the one before the second parameter. It means if I put (2, 5) as parameters then it returns the String from 2 to 4.

(8) toLowerCase()

This method returns String that changed all of the upper cases in the String into lower cases. It also doesn’t affect to the original String and doesn’t need parameter.

(9) toUpperCase()

It returns String that changed all of the lower cases in the String into upper cases.

Well that’s all for today guys! I’ll bring some more of the String method on the next sesh! 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