String Handling :: Part 2

string handling :: futureX


String comparison:


There are three ways to compare String objects:


  • By equals() method
  • By = = operator
  • By compareTo() method



By equals() method:

equals() method compares the original content of the string.It compares values of string for equality.String class provides two methods:


public boolean equals(Object another){}
compares this string to the specified object.

public boolean equalsIgnoreCase(String another){}
compares this String to another String, ignoring case.


class Simple{
 public static void main(String args[]){

   String s1="salman";
   String s2="salman";
   String s3=new String("salman");
   String s4="shahrukh";

   System.out.println(s1.equals(s2));//true
   System.out.println(s1.equals(s3));//true
   System.out.println(s1.equals(s4));//false
 }
}


By == operator:

The = = operator compares references not values.


class Simple{
 public static void main(String args[]){

   String s1="Sachin";
   String s2="Sachin";
   String s3=new String("Sachin");

   System.out.println(s1==s2);//true (because both refer to same instance)
   System.out.println(s1==s3);//false(because s3 refers to instance created in nonpool)
 }
}


By compareTo() method:

compareTo() method compares values and returns an int which tells if the values compare less than, equal, or greater than.

Suppose s1 and s2 are two string variables.If:

s1 == s2          :0
s1 > s2            :positive value
s1 < s2            :negative value


class Simple{
 public static void main(String args[]){

   String s1="Sachin";
   String s2="Sachin";
   String s3="Ratan";

   System.out.println(s1.compareTo(s2));//0
   System.out.println(s1.compareTo(s3));//1(because s1>s3)
   System.out.println(s3.compareTo(s1));//-1(because s3 < s1 )
 }
}


String Concatenation:



There are two ways to concat string objects:


  • By + (string concatenation) operator
  • By concat() method


 By + (string concatenation) operator

String concatenation operator is used to add strings.

For Example:

class Simple{
 public static void main(String args[]){

   String s="Sachin"+" Tendulkar";
   System.out.println(s);//Sachin Tendulkar
 }
}


The compiler transforms this to:

String s=(new StringBuilder()).append("Sachin").append(" Tendulkar).toString();

String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method.String concatenation operator produces a new string by appending the second operand onto the end of the first operand.The string concatenation operator can concat not only string but primitive values also.

For Example:

class Simple{
 public static void main(String args[]){

   String s=50+30+"Sachin"+40+40;
   System.out.println(s);//80Sachin4040
 }
}


If either operand is a string, the resulting operation will be string concatenation. If both operands are numbers, the operator will perform an addition.


 By concat() method

concat() method concatenates the specified string to the end of current string.

Syntax : public String concat(String another){}

class Simple{
 public static void main(String args[]){

   String s1="Sachin ";
   String s2="Tendulkar";

   String s3=s1.concat(s2);

   System.out.println(s3);//Sachin Tendulkar
  }
}

Substring:



You can get substring from the given String object by one of the two methods:
       

public String substring(int startIndex)

This method returns new String object containing the substring of the given string from specified startIndex (inclusive).

public String substring(int startIndex,int endIndex):

This method returns new String object containing the substring of the given string from specified startIndex to endIndex.

In case of string

startIndex    :starts from index 0(inclusive).
endIndex      :starts from index 1(exclusive).

class Simple{
 public static void main(String args[]){

   String s="Sachin Tendulkar";
   System.out.println(s.substring(6));//Tendulkar
   System.out.println(s.substring(0,6));//Sachin
 }
}



                                                             JAVA TUTORIALS HOMEPAGE

0 comments:

Sony Xperia Z specifications


GENERAL

2G Network GSM 850 / 900 / 1800 / 1900 - C6602, C6603
3G Network HSDPA 850 / 900 / 2100 - C6603
                  HSDPA 850 / 900 / 1700 / 1900 / 2100 - C6602
4G Network LTE 800 / 850 / 900 / 1800 / 2100 / 2600 - C6603
SIM                 Micro-SIM
Announced 2013, January
Status         Coming soon. Exp. release 2013, March


BODY

Dimensions 139 x 71 x 7.9 mm (5.47 x 2.80 x 0.31 in)
Weight         146 g (5.15 oz)
                  - IP57 certified - dust and water resistant
                        - Water proof up to 1 meter and 30 minutes

sony xperia z body :: futureX


DISPLAY

Type         TFT capacitive touchscreen, 16M colors
Size                 1080 x 1920 pixels, 5.0 inches (~441 ppi pixel density)
Multitouch Yes, up to 10 fingers
Protection Shatter proof and scratch-resistant glass
                   - Timescape UI
                         - Sony Mobile BRAVIA Engine 2


sony xperia Z display :: futureX 

SOUND

Alert types Vibration; MP3 ringtones
Loudspeaker Yes
3.5mm jack Yes


MEMORY

Card slot microSD, up to 32 GB
Internal 16 GB, 2 GB RAM


DATA

GPRS         Up to 107 kbps
EDGE         Up to 296 kbps
Speed         HSDPA, 42 Mbps; HSUPA, 5.8 Mbps; LTE, Cat3, 50 Mbps UL, 100 Mbps DL
WLAN         Wi-Fi 802.11 b/g/n, Wi-Fi Direct, DLNA, Wi-Fi hotspot
Bluetooth Yes, v4.0 with A2DP
NFC         Yes
USB                 Yes, microUSB v2.0 (MHL)


CAMERA

Primary 13.1 MP, 4128x3096 pixels, autofocus, LED flash
Features Geo-tagging, touch focus, face detection, image stabilization, HDR, sweep panorama
Video Yes, 1080p@30fps, continuous autofocus, video light, video stabilizer, HDR
Secondary Yes, 2.2 MP, 1080p@30fps


FEATURES

OS Android OS, v4.1.2 (Jelly Bean), planned upgrade to v4.2 (Jelly Bean)
Chipset Qualcomm MDM9215M / APQ8064
CPU         Quad-core 1.5 GHz Krait
GPU Adreno 320
Sensors Accelerometer, gyro, proximity, compass
Messaging SMS (threaded view), MMS, Email, IM, Push Email
Browser HTML5
Radio Stereo FM radio with RDS
GPS         Yes, with A-GPS support and GLONASS
Java Yes, via Java MIDP emulator
Colors Black, White, Purple
          - SNS integration
                - TV-out (via MHL A/V link)
                - Active noise cancellation with dedicated mic
                - MP4/H.263/H.264/WMV player
                - MP3/eAAC+/WMA/WAV/Flac player
                - Document viewer
                - Photo viewer/editor
                - Voice memo/dial
                - Predictive text input

sony Xperia Z :: futureX 

BATTERY  

Non-removable Li-Ion 2330 mAh battery

Stand-by         Up to 550 h (2G) / Up to 530 h (3G)
Talk time Up to 11 h (2G) / Up to 14 h (3G)
Music play Up to 40 h

0 comments:

Copyright © 2013 futureX | Blogger Template by Clairvo