Sunday 1 September 2019

Java String Class and String manipulation

Hi reader,

Welcome, I will take you through String basics in Java and I hope you will have a deeper understanding at the end of the day.

Objectives on this post.

1. Deeper understanding of String class and String manipulation in Java.

Subtopics

1. The String Class (extends Object, implements Serializable, Comparable and charSequence interfaces)

2. Two ways of creating a string

- via String literal (add into string pool in the heap)

- new keyword (creates an object in the heap)

3. String manipulations

4. String, String Builder, and String Buffer

Let's get started.

A String is a sequence of characters. A character is a letter, a number, space, punctuation mark, or a symbol that can be typed on a computer. In java, a character or "char" is a single character, say a letter like 'A', a number like '9', a special character like '^' caret, etc. While char is a primitive type, String is a reference type. A primitive data type is the most basic type that acts as a building block for other data types. In Java, there are 8 primitive types namely: boolean, byte, char, short, int, long, float and double. In Java world, a reference type is a data type that is based on a class rather than on one of the primitive types.

No comments:

Post a Comment