This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Vargs in place of String array as argument to main() method please explain output  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)public class ProgramArgument {

2) public ProgramArgument() { System.out.println(this); }

3) public static void main(String...args) {

4) new ProgramArgument();

5) System.out.println(args);
6) }
7) }
/* I obtain output
ProgramArgument@3e25a5
[Ljava.lang.String;@19821f

when i make comment the 4th statement I obtain output
[Ljava.lang.String;@3e25a5

Can anyone explain why this output and what's the reason of this output.....
Thanks */

 
Sheriff
Posts: 21328
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Ljava.lang.String;@3e25a5

The first [ always means it's an array. Next comes the type; I for int, B for byte, Z for boolean and L<class name>; for classes. So in this case, the [Ljava.lang.String; indicates it's a String array.
The part after the @ is the hexidecimal representation of the hash code.
 
Marshal
Posts: 59101
180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

As well as what Rob told you, have a look at the Object class and its un-overridden toString() method.
 
Nishant Arora
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks dear
 
Paper jam tastes about as you would expect. Try some on this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!