STRINGS IN JAVA

“Wow !!!! Now Thus Intereeessssting” That was how i exclaimed when i saw these interesting features of the STRING class in java. All this while when i wanted to convert a character array to a string , i had to go through a loop. For example

String password = “” ;
char[] pass = this.txtPassword.getPassword();
for (int i = 0; i < pass.length; i++) {
password = password + pass[i];
}

But this char[] pass can easily be converted to string by just a line of code:

char[] pass = this.txtPassword.getPassword();
String password=new String(pass);

Also another interesting feature of the string class is that you can easily get the string value out of a byte array and vice versa with so much ease. check this.

byte[] array=”sdfdfd”.getBytes();
String string=new String(array);

These are not all, there are more interesting features, exploree!!!!

Fellows, enjoy the weekend

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s