Java Learning Made Easy by Dheeraj Mehrotra - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

String Functions (Cont.)

02412.jpg02413.jpg02414.jpg02415.jpg02416.jpg02417.jpg

(xi). indexOf();

02418.jpg02419.jpg

FORMAT: a1.indexOf(‘d’);

02420.jpg

USAGE:

02421.jpg

This returns the position of the first occurrence of ‘d’ in the string a1.

02422.jpg

(xii). indexOf(); [another format]

02423.jpg

FORMAT: a1.indexOf(‘d’,n);

02424.jpg

USAGE:

02425.jpg02426.jpg02427.jpg

This format gives the position of ‘d’ starting from the nth position in the

02428.jpg

string variable a1.

02429.jpg02430.jpg

(xiii). compareTo()

02431.jpg02432.jpg

FORMAT: a1.compareTo(a2);

02433.jpg02434.jpg

USAGE:

02435.jpg02436.jpg

This function returns negative if a1 is less than a2, positive if a1 is greater than a2 and zero if a1 is equal to a2.

02437.jpg02438.jpg02439.jpg02440.jpg02441.jpg02442.jpg02443.jpgattention@computerscienceexpertise.com

 

02444.jpg02445.jpg02446.jpg02447.jpg02448.jpg02449.jpg02450.jpg02451.jpg02452.jpg02453.jpg02454.jpg02455.jpg02456.jpg02457.jpg02458.jpg02459.jpg02460.jpg02461.jpg02462.jpg02463.jpg02464.jpg02465.jpg