File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes confuse code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "confuse code" Watch "confuse code" New topic
Author

confuse code

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Jan 12, 2005
Posts: 4
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

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Oct 12, 2000
Posts: 5093
and you think you can pass the SCJP exam?
you don't even comprehend basic programming concepts like arrays...


42
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Jan 12, 2005
Posts: 213
i am completely agree with rathi ji . either moderator should throw out jeroen or he should leave this friendly community .


:d
Jagadeesh Kumar Macherla
Greenhorn

Joined: Jan 12, 2005
Posts: 4
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

Joined: Oct 11, 2004
Posts: 3830
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 ....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confuse code
 
Similar Threads
convert int ,double to string
initialisation and reinitialisation doubt.....
Vector and Array please help
how to get reverse string
StringTokenizer not helping in splitting