Krivalar Tutorials 
Krivalar Tutorials

Java Arrays and Strings


<<Previous

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[]=
	{'H','e','l','l','o',
	' ','w','o','r','l','d'};
int listOfNumbers[] =
	{1,2,3,6,7,8,10,11,14,15};
float arrayOfProductPrice[] =
	{10.45f,23.22f,87.45f,32.1011f};
double arrayOfSalaries[]=
	{45000.00,34000.56,3400.50};
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[]=
	{'H','e','l','l','o',
	' ','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");
System.out.println(msg);

String Concatenation

Strings can be concatenated as shown below:


String msg1 = "Thank ";
String msg2 = "you ";
System.out.println(
	msg1+msg2+"world");

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


System.out.println(
	"My ID is " + 1200);

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


<<Previous

Next >>





















Searching using Binary Search Tree