Javatpoint Logo

Is java Call by value or call by reference ?

By: patila*** On: Tue May 02 15:25:43 IST 2017     Question Reputation2 Answer Reputation0 Quiz Belt Series Points0  2Blank User
I have read on this site java is call by value then why i am getting such outputs-

import java.util.ArrayList;

public class JavaDemo {

public static void main(String[] args) {

ArrayList<Integer> arrayList = new ArrayList<Integer>();
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);
modify1(arrayList);
System.out.println("After method call=> " + arrayList);

StringBuffer buffer = new StringBuffer("System");
modify2(buffer);
System.out.println("After method call=> " + buffer);
}

static void modify1(ArrayList al) {
al.add(4);
al.add(5);

}

static void modify2(StringBuffer buffer) {
buffer.append("MODIFIED..");
}
}


OUTPUT---
After method call=> [1, 2, 3, 4, 5]
After method call=> SystemMODIFIED..
Up0Down