Originally posted by Sunali Anu: Use Collection.swap method to do the swapping... That works...
The task is to swap two array elements, not two collection elements. You don't mean to suggest converting the array to a List, then to call swap, and then to convert the List back to an array? [ June 25, 2007: Message edited by: Ulf Dittmer ]
Ping & DNS - updated with new look and Ping home screen widget
Joined: May 09, 2007
Ya Thanks God You have understnad my problem,because before your replys i think that i a duffer,but thanks to all that you solve my problem by saying that its not possible in java,but it should be,waiting for your reply,and Andris Jekabsons this is not what i want actully this the problem that i have, i want to swap original objects,andd Benerjee thanks that you understand my problem....waiting for your replys,
Andris Jekabsons has already told you what to do. You have to pass a (value of the) reference to the array, and the two indices you want to swap. The method you suggested in the thread transferred from the advanced forum, which is the same as Prosenjit Banerjee suggested, will not swap the original array, as Jeanne Boyarsky has already told you.
You have already had two satisfactory answers on your other thread.
I don't understand what you are saying about moving the internal details. Do you mean which memory location you are going to put the data in? You mean taking the contents of memory location 123456 and putting them in location 234567 and the contents of 234567 into 123456? A concept which has no place in a high-level language. Even pointers in C don't give that sort of control. It is far too error-prone. Also (Bruce Eckel, Thinking in Java, 4/e, Upper Saddle River: Prentice-Hall  page 178ff) the garbage collector can move objects around in memory, so the reference which used to be 123456 can become 345678. In a high-level language you only want to deal with variable names, never with the memory locations.
Joined: May 09, 2007
Thanks Cambell,Actully you know what, one of my friend who is from .Net Lovers,he asked me this Question that is it possible but i was unable to answer him,and Now I understand that it is not possible to swap original objects in array in JAVA, you can only swap refrences....Ne ways thanks to all,and sorry if any one of you mind any thing