• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array element asignment  RSS feed

 
Pooja Pawar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The above program is compiled with the command line:

javac FunWithArgs.java
and then run with:
java FunWithArgs a b c

Output is b [L.java.lang.string;@15db9742

As per my understanding args[0][0]= a, args[0][1]=b, args[0][2]=c.
I am unable to understand the element assignment at args[] .

could anybody help me understand the structure and element assignment of this array?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pooja Pawar wrote:
As per my understanding args[0][0]= a, args[0][1]=b, args[0][2]=c.
I am unable to understand the element assignment at args[] .


The "args" in the method that takes an args[][], is an array of string arrays. In your example, it only has one element, which is the string array passed into the parameter. This is why you can only dereference the first element at index zero. Trying to do anything else will generate an error.

Once you deference the array to the string array, at args[0], you can further dereference it to the strings, which in your example, contains three strings, at index 0, 1, and 2 respectively. This means, the three strings can be reached at args[0][0], args[0][1], and args[0][2], respectively.

Henry
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unable to understand the element assignment at args[] .

It's an array.  What you are seeing when you print it is a representation of its location in memory.  If you want to see a representation of its contents, try:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!