Krivalar Tutorials 
Krivalar Tutorials

Java Arrays and Strings


Next >>

Java Arrays

In Java, Array can be created to hold a sequence of data - which can be of any primitive data type or any object

char charMsg[]=
	' ','w','o','r','l','d'};
int listOfNumbers[] =
float arrayOfProductPrice[] =
double arrayOfSalaries[]=
Object arrayOfObject[]={};

Java String

In Java, String is an object. String objects are immutable. That is, a String object itself can not be modified in memory. If we need a modified String, A new String would be created in memory with the change.

In Java, Strings use Unicode by default. Unicode can be used to represent content in any of the languages in the world

Creating a String

A String object can be created in any of the ways described below:

String msg = "Hello Good";

char charMsg[]=
	' ','W','o','r','l','d'};
String mesg =
	new String(charMsg);

String message=
	new String("Hello World");

Printing a String

String can be printed as shown below:

System.out.println("Hello World");

String Concatenation

Strings can be concatenated as shown below:

String msg1 = "Thank ";
String msg2 = "you ";

Strings can be concatenated with other datatypes as well as shown below:

	"My ID is " + 1200);

This will print "My ID is 1200" in the console


Next >>