String is a Class in java and defined in java.lang package. It’s not a primitive data type like int or long. String class represents character Strings. String is used in almost all the Java applications and there are some interesting facts we should know about String. String is immutable and final in Java and JVM uses String Pool to store all the S...

Read More

There are 2 ways of creating a String Object in Java. One is using new operator and another one is using string literals. The objects created using new operator are stored in the heap memory and objects created using string literals are stored in string constant pool.     //Creating string object using new operator     String s = new String("This i...

Read More

String is the most used Object in Java. Hence, java has a special arrangement to store the string objects. String Constant Pool is one such arrangement. String Constant Pool is the memory space in heap memory specially allocated to store the string objects created using string literals. In String Constant Pool, there will be no two string objects h...

Read More

When there are two string objects created using the new operator and they are concatenated using the + operator there definitely is a new string object being created, since the original operands were created using the new operator. But what happens when two string literals are concatenated using the + operator. As you remember string literals are p...

Read More

As we have already discussed string is an immutable object and any manipulation performed on the string objects results in a new string object. So any manipulation performed create a new object which goes on to the heap. This can lead to serious memory issues. So Java also provides us with an alternate option of StringBuffer. StringBuffer is meant ...

Read More

A String is an immutable type supported by Java. It is nothing but a collection of characters. The implementation of string is final character array, the size of which is defined at the time of declaration. There are no getters or setters in a string class. The class has a lot of utility methods defined for string manipulation like concat, indexof,...

Read More

There are two ways to check if two Strings are equal or not. Using “==” operator or using equals() method of Object class. When we use “==” operator, it checks for value of String as well as reference but in our programming, most of the time we are checking equality of String for value only. So we should use equals method to check if two Strings ar...

Read More

Returns a canonical representation for the string object. A pool of strings, initially empty, is maintained privately by the class String. When the intern method is invoked, if the pool already contains a string equal to this String object as determined by  the equals(Object) method, then the string from the pool is returned. Otherwise, this String...

Read More

Since String is immutable, its hashcode is cached at the time of creation and it doesn’t need to be calculated again. This makes it a great candidate for key in a Map and its processing is fast than other HashMap key objects. This is why String is mostly used Object as HashMap keys.

Read More

String is the most used Object in Java. Hence, java has a special arrangement to store the string objects. String Constant Pool is one such arrangement. String Constant Pool is the memory space in heap memory specially allocated to store the string objects created using string literals. In String Constant Pool, there will be no two string objects h...

Read More

Yes Strings are thread safe. Since String is immutable it can safely shared between many threads. We don't need to synchronize String operation externally.

Read More

Interned Strings avoid duplicate Strings. Interning Strings save RAM (Random Access Memory) at the expense of more CPU (Central Processing Unit) time to detect and replace duplicate Strings. There is only one copy of each String that has been interned, no matter how many references point to it. Since Strings are immutable, if two different methods ...

Read More

String is most commonly used class in Java programming language. Java also provides two other classes StringBuffer and StringBuilder for working with String. We need to carefully choose between these three depending on the requirement. Thus it is important to understand difference among them. The basic difference is  String class objects are immuta...

Read More

java.util.StringTokenizer breaks up Strings into chunks at delimiters and hands them to you one at a time. The tokenization method is much simpler than the one used by the StreamTokenizer class. The StringTokenizer methods do not distinguish among identifiers, numbers, and quoted strings, nor do they recognize and skip comments. The set of delimite...

Read More

FOLLOW US ON LinkedIn



Explore Tutu'rself