Array
public Move[] getPossibleMoves() {
return (Move[])possibleMoves.toArray(new Move[0]);
hi i am working on chess and this is a piece of code which sits inside the move package ,which contains all the possible move...
i want to know what exaclt will be the outcome of the code... what will it return?
thankx
> ...> i want to know what exaclt will be the outcome of the> code... what will it return?Is this a trick question? My answer is: an array of Move's
thankx buddy .. i am new to java tat's y i am not sure what will b the outcome .. i am looking at huge peice of code ... tat's y pretty confused.. well how good r u in java .? can u help me out please
> thankx buddy .. i am new to java tat's y i am not
> sure what will b the outcome .. i am looking at huge
> peice of code ... tat's y pretty confused..
I understand: you found the source on the web (or from a book). I can assure you: that is not the way to learn Java. I suggest starting from the beginning and then working your way up towards something more complicated (like writing a chess application).
Sun's tutorials are pretty good:
http://java.sun.com/docs/books/tutorial/reallybigindex.html
> well how good r u in java .? can u help me out please
My cooking skills are better, but I know the basics of Java pretty well.
>> I understand: you found the source on the web
its noting like i get the code from net and paste it.. i got complete reference material and also have been working on java.. but the prob is not much deep....
well my id is aravindraaman@hotmail.com if in case u can help me out please mail me
thankx for the help so far
> its noting like i get the code from net and paste
> it.. i got complete reference material and also have
> been working on java.. but the prob is not much
> deep....
?
Since you had to ask what the method you posted returns, I assumed you know very little Java, because the return type of a method can be read from the method signature...
> well my id is aravindraaman@hotmail.com if in case u
> can help me out please mail me
> thankx for the help so far
No, I will not e-mail you. If you have a question, feel free to post it here on the forum.
> thankx buddy .. i am new to java tat's y i am not> sure what will b the outcome .. i am looking at huge> peice of code ... tat's y pretty confused.. well how> good r u in java .? can u help me out pleasecn u plz us all th lttrs on ur kybrd?
> > thankx buddy .. i am new to java tat's y i am not
> > sure what will b the outcome .. i am looking at huge
> > peice of code ... tat's y pretty confused.. well how
> > good r u in java .? can u help me out please
>
> cn u plz us all th lttrs on ur kybrd?
eye 2nd tht!1!
public Move[] getPossibleMoves() {
return (Move[])possibleMoves.toArray(new Move[0]);
}
It's the funny way Java has to convert a Collection to an array. I suppose possibleMoves is declared a Collection of some kind (like List or ArrayList, for example)? Have you learned to use the API docs yet? They're no. 1. Look at
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collection.html#toArray(java.lang.Object[]).
Message was edited by:
OleVV
OleVVa at 2007-7-12 10:33:22 >

By the way, this is the Java 1.4 syntax. It gets a little simpler in Java 1.5, so you may want to go with version 1.5 or 1.6.
OleVVa at 2007-7-12 10:33:22 >
