Java array :Java pass by reference and pass by value? -


i trying reverse bitmap array, without modifying source array. problem source array getting reversed. doing wrong or suppose other way? help.

private galleryadapter galleryadapter; private reversegalleryadapter rgalleryadapter;    public void oncreate(bundle savedinstancestate) {     galleryadapter = new galleryadapter(this, imagethumbnails, imagepaths,             videothumbnails, videopaths);      imagegrid.setadapter(galleryadapter);      rgalleryadapter = new reversegalleryadapter(this, reversebarray(videothumbnails), reversesarray(videopaths),             reversebarray(imagethumbnails), reversesarray(imagepaths));      imagegrid2.setadapter(rgalleryadapter); }  private bitmap[] reversebarray(bitmap[] v){     bitmap[] btemp;     btemp = v;     int len = btemp.length;     bitmap temp;     (int = 0; < len/2; i++)     {         temp = btemp[i];         btemp[i] = btemp[len-1 - i];         btemp[len-1 - i] = temp;     }     return btemp; }  private string[] reversesarray(string[] s){     string[] stemp;     stemp =s;     int len = stemp.length;     string temp;     (int = 0; < len/2; i++)     {         temp = stemp[i];         stemp[i] = stemp[len-1 - i];         stemp[len-1 - i] = temp;     }     return stemp; } 

with btemp = v; referring same object.

you can use in case clone() method make copy of array:

btemp = v.clone(); 

then can freely modify , return it.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -