Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the responsive-lightbox domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114
String methods - Concat and contains - Testingpool

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.

public class StringMethodsEx {

	public static void main(String[] args) {
		
		String val1 = "Hello world!!";
		String val2 = "";
		
		System.out.println(val2.concat("New string object"));  // new string
		System.out.println(val1.concat("How ").concat("are ").concat("you."));
	}
}
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.

public class StringMethodsEx {

	public static void main(String[] args) {
		
		String val1 = "Hello world!!";
		
		System.out.println(val1.contains("Hello"));  //returns true
		System.out.println(val1.contains("Universe"));  //returns false
		
	}
}
Output:
true
false
Ask Question
Have any question or suggestion for us?Please feel free to post in Q&A Forum
Avatar photo

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...