• 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: 21255
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.
 
Sheriff
Posts: 57834
178
  • 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
 
Oh. Hi guys! Look at this tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!