• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confuse code

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int x = ( int ) ( Math.random()*5 );
String name = new String[] { "a","b","c","d","e" }[x];

I am not getting the second line please help ...
thanks a lot ...
 
Jagadeesh Kumar Macherla
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope u unserstood the first line.. it would return a random number from 0 - 4.
In the second line => new String[] { "a","b","c","d","e" }, is nothing but a string array it is equivalent to declaring an array and assinging it.
String[] arrayStrings = new String[] { "a","b","c","d","e" };
String name = arrayStrings[x];//this would assing the element corresponding to the random index..
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks jagadeesh ,
it is using anonymous array ... right ?

this line should be like this in your post , i think .


but , it was really cool ...
[ January 13, 2005: Message edited by: rathi ji ]
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and you think you can pass the SCJP exam?
you don't even comprehend basic programming concepts like arrays...
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeroen Wenting:
and you think you can pass the SCJP exam?
you don't even comprehend basic programming concepts like arrays...


Are you here to make insults of people ... why you are here ... you don't make any question ... You don't answer any question ( oh sorry , that require mind , so its just impossible for you ) ... I am sure out of your 3000 message 2900 are waste .... actually you are whole waste .... I am dam sure that you are very inferior , failure kind of person .... no body is happy with you ( even your wife ( if she is living with you till now ...) )
 
pooja jain
greenhorn
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am completely agree with rathi ji . either moderator should throw out jeroen or he should leave this friendly community .
 
Jagadeesh Kumar Macherla
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
s.. its an anonymous array.. i am not sure if u can not initialize an array with String[] s = new String[]{"a",..}.. it could be possible..plz check it by writing a small program..
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yaa jagadeesh ,
what happened to us .... its an anonymous array object so definately it is refered by a array reference .... it is valid ...
thanks a lot ....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic