String methods – Concat and contains

In this post, we will see 2 string methods which are  concat and contains.

String concat(String str):

The method appends a specified string to the end of this string.

If the length of the string is 0, after concatenating a new string will return. We can concatenate multiple strings as well as shown in the code below.

Output:
New string object
Hello world!!How are you.

boolean contains(CharSequence s):

This method finds the sequence of characters in the any string and returns true if matches ,else false.

Output:
true
false
Ask Question
Have any question or suggestion for us?Please feel free to post in Q&A Forum
Print Friendly, PDF & Email
String methods - charAt() and compareTo()
String methods - startsWith and endsWith
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...