Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Java programming notes

Rating
-
Sold
-
Pages
8
Uploaded on
12-10-2024
Written in
2024/2025

It has some details about th java laanguage

Institution
Course

Content preview

5/19/2021 Java String - javatpoint




Java String
In Java, string is basically an object that represents sequence of char values. An array
of characters works same as Java string. For example:


char[] ch={'j','a','v','a','t','p','o','i','n','t'};

String s=new String(ch);


is same as:


String s="javatpoint";


Java String class provides a lot of methods to perform operations on strings such as
compare(), concat(), equals(), split(), length(), replace(), compareTo(), intern(),
substring() etc.




The java.lang.String class implements Serializable, Comparable and CharSequence
interfaces.




CharSequence Interface


https://www.javatpoint.com/java-string 1/8

, 5/19/2021 Java String - javatpoint

The CharSequence interface is used to represent the sequence of characters. String,
StringBuffer and StringBuilder classes implement it. It means, we can create strings in
java by using these three classes.




The Java String is immutable which means it cannot be changed. Whenever we change
any string, a new instance is created. For mutable strings, you can use StringBuffer and
StringBuilder classes.

We will discuss immutable string later. Let's first understand what is String in Java and
how to create the String object.




What is String in java
Generally, String is a sequence of characters. But in Java, string is an object that
represents a sequence of characters. The java.lang.String class is used to create a
string object.


How to create a string object?

There are two ways to create String object:


1. By string literal

2. By new keyword




1) String Literal
Java String literal is created by using double quotes. For Example:


String s="welcome";


Each time you create a string literal, the JVM checks the "string constant pool" first. If
the string already exists in the pool, a reference to the pooled instance is returned. If
the string doesn't exist in the pool, a new string instance is created and placed in the
pool. For example:


String s1="Welcome";

String s2="Welcome";//It doesn't create a new instance


https://www.javatpoint.com/java-string 2/8

Written for

Institution
Course

Document information

Uploaded on
October 12, 2024
Number of pages
8
Written in
2024/2025
Type
Class notes
Professor(s)
Panjak
Contains
Programming students

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
khushisharma8

Get to know the seller

Seller avatar
khushisharma8 Govt. Polytechnic hamirpur
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
6
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions