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

The equals method in String class and that of a String Array object

 
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
  As I read the equals method of the String class overrides the default implementation in the Object class and hence str1.equals(str2) will true if they have same content even if they are different String Objects. This is not the same for a String array Object. Here strarray1.equals(strarray2) are same only then they refer to the same array object (which is the implementation in the Object Superclass). My question is :- Is String array a class in itself, if so which class ?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays are objects, and an object is always an instance of a class, so yes, an array is also an instance of a class.

Classes for arrays are however built-in in Java, and not documented in the API documentation.

You can use this to get the name of the class for String arrays:

This will print the following, which is the internal name of the class for String arrays:

[Ljava.lang.String;
 
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
And every array IS-A Object.
 
Prabir Sarkar
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jesper and Roel for your crystal clear explanation.
 
Sasparilla and fresh horses for all my men! You will see to it, won't you tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic