This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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: 23834
140
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!