Kaskus

Tech

Pengaturan

Mode Malambeta
Gambar

Lainnya

Tentang KASKUS

Pusat Bantuan

Hubungi Kami

KASKUS Plus

© 2024 KASKUS, PT Darta Media Indonesia. All rights reserved

itian.konguAvatar border
TS
itian.kongu
Java String
What is a string?
In C, C++, a string represents an array of characters (last character ends with ‘\0’).
In Java, a string represents the object of String class. We also have character array in java.

Is String a class or a datatype?
String is a class defined in java.lang package. In Java, every class is considered as user defined data type. So we can take string as a data type.

Ways to create a String:
Method 1: By assigning a group of characters to a string type variable.
Syntax:

String <variable_name>;
<varaible_name> = “string”;
Example:
String name;
name = “Hari”;
Declaration and assignment can be made by a single statement. This is just a simplification of the above.

Syntax:
String <variable_name> = value;
Example:
String name = “Hari”;

Method 2: Creating an object to string class by allocating memory using new operator.

Syntax:
String <object> = new String(“value”);
Example:
String name = new String(“Hari”);

Method 3: Converting the character array into strings.

Syntax:
String <object> = new String(<Char_Array>emoticon-Wink;
Example:
char n[] = {‘H’,’a’,’r’,’i’};
String name = new String(n);

Note: A string can be empty with no characters inside it.

Example:
String s=””
To Know more about Java Strings Visit
String
String Buffer
String Builder
0
710
4
GuestAvatar border
Komentar yang asik ya
Mari bergabung, dapatkan informasi dan teman baru!
Programmer Forum
Programmer Forum
KASKUS Official
20.2KThread4.5KAnggota
Urutkan
Terlama
GuestAvatar border
Komentar yang asik ya
Ikuti KASKUS di
© 2024 KASKUS, PT Darta Media Indonesia. All rights reserved.