Home » Core Java » lang » Page 2

lang

Java String getBytes Example

We all know that every single piece of code consists of bytes. So do the Strings, this Java class type, that can represent text and words inside a Java program. In order to convert bytes into characters, Java needs to know what to represent, in which language, and what each character means in every language in the world. This is ...

Read More »

Java String isEmpty Example

When we talk about Strings in Java, we can imagine them as arrays of characters. An empty Java String, is considered as the not null String that contains zero charachers, meaning its length is 0. However, a Java String that might only contain the whitespace character is not considered as empty, it is considered to contain one character and its ...

Read More »

StringBuilder Java Example

In this post, we feature a comprehensive StringBuilder Java Example. StringBuffer in Java is the same as StringBuilder, but the first is thread-safe. At the end of this article, we will create an abstract TestBase class which shows StringBuffer ‘s common methods. 1. Introduction StringBuilder object seems like a String object but with the characteristics of an array. Every object ...

Read More »

Java String intern Example

In Java, when we talk about String interning, we describe how Java stores only one copy of every distinct String value in the string pool, in order to reuse String objects to save memory from a program. This practically means, that each String object is stored only once in memory, regardless of how many times the same String may appear ...

Read More »

Java String reverse Example

In this example we are going to see how to reverse a String in Java. We are going to see how to this, very conveniently using a StringBuffer, and two other solutions using recursion and simply using a character array. Let’s see the examples. 1. Reversing a String using StringBuffer Let’s see how you can use a StringBuffer to reverse ...

Read More »

Java String split Example

In this Java String split example we are going to see how to split a String in Java into smaller sub strings. It is extremely common to want to split a String into parts. These parts are separated by a specific delimiter. And in order to avoid parsing the String yourself, Java offers split API method. 1. Using split It ...

Read More »

Java String pool Example

In this example we are going to talk about a very interesting subject, Java String pool. As the name suggest, String pool is a pool, or else a set, of String objects located in a special place in Java Heap. Java creators introduced this String pool construct as an optimization on the way String objects are allocated and stored. String ...

Read More »

Java String replaceAll example

In this example we are going to see how to use replaceAll String class API method. With replaceAll, you can replace all character sequences and single characters from a String instance. As you know, String objects are immutable. This means, that every time you try to change its value, a new String object is created, holding the new value. So ...

Read More »

Java String lastIndexOf Example

As we disscused in a previous post about Java String indexOf() Example, many times we need to search for a character set in a Java String. Thus we need a “tool”, a method that will help us make it. So, in this example we are going to talk about identifying characters and subsequences of characters through Java Strings, with the method ...

Read More »

String indexOf Java Example

In this post, we feature a comprehensive String indexOf Java Example. We also describe an example of the lastIndexOf in Java . It is often important to search for a character or a character set in a Java String. For example, in the parsing of Java Strings, we might want to provide the possibility for a search through strings, in order to ...

Read More »