Java-String

String A string is a sequence of characters. In Java, string is the most important data type. A string is enclosed in quotation marks, as in the case of the example “KrugerPark”. But the quotation marks are not themselves part of the string. The string are useful in representing various types of non-numeric data, such … Read more…

Java-Get Length

Get Length The String class defines a number of methods that allow us to accomplish a variety of string manipulation tasks. The number of characters in a string provided by the length( ) method of the String class. Since it is an instantiated method, we have to invoke it from an object of the String … Read more…

Java-String Concatenation

String Concatenation Java defines one operator for string object such as “+”, it is used to concatenate two string. For example, in the following program, the value of the variable ‘a’ and ‘b’ is being converted to a string that represents this value as a decimal digit character. This is prompted by the fact that it … Read more…

Java-String Comparison

String Comparison We use the == operator for comparing the values of two variables or expressions of any data type, such as int, float, double, char and boolean. But we have to use the equals( ) method of the String class for comparing two strings. This method is used to find the contents are same, … Read more…

Java-new String vs String literals

new String vs String literals When you create String object using new operator, it always create a new object in heap(one of memory section). On the other hand, if you create object using string literal, it may return an existing object from String pool(one of memory section), if it’s already exists. Otherwise it will create a … Read more…

Java-Extracting Character

Extracting Character The charAt( ) method provides the character at the specified index position. The starting value of the index in the case of a string is zero. For example, in the following program, the character at position 3 in the string “hajsof” is ‘s’. Thus, the str1.charAt(3) method will return the character ‘s’. Concat … Read more…