Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

String class

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


this is Listing 4.1 Method definition of the equals method from the class String from Mala Gupta book.

and i cant understand whats happening at line 1,2,3.


 
author
Posts: 23877
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sukhitha sunil wrote:
and i cant understand whats happening at line 1,2,3.



1. Declaring a variable, and assigning the size of the string. This size is held in a private variable of the String class. And the reason a copy is needed is that it will be used to loop through the character array that holds the characters of the string.

2. Checking the string size, with the size of the string to be compared. There is no reason to check the characters if the sizes are different.

3. Get the character array of the string to be compared. The following lines will loop through the two arrays to check if the characters are the same. And of course, as with the size, the array is also a private variable of the String class.

Henry
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sukhitha sunil wrote:and i cant understand whats happening at line 1,2,3.


Luckily you don't need to know the internal implementation of the equals() method of the String class for the actual exam. You only need to know when this method will return true or false.
 
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic