Linked Questions

251 votes
7 answers
307k views

Arrays are not a primitive type in Java, but they are not objects either, so are they passed by value or by reference? Does it depend on what the array contains, for example references or a primitive ...
Froskoy's user avatar
  • 3,045
55 votes
6 answers
29k views

Possible Duplicate: Is Java “pass-by-reference”? I found an unusual Java method today: private void addShortenedName(ArrayList<String> voiceSetList, String vsName) { if (null == vsName)...
Troy Nichols's user avatar
  • 1,234
46 votes
6 answers
37k views

Possible Duplicate: Is Java pass by reference? public class myClass{ public static void main(String[] args){ myObject obj = new myObject("myName"); changeName(obj); ...
MBZ's user avatar
  • 479
37 votes
10 answers
36k views

I have the following code: public class Main { static void swap (Integer x, Integer y) { Integer t = x; x = y; y = t; } public static void main(String[] args) { ...
witzar's user avatar
  • 770
33 votes
8 answers
38k views

I thought almost all languages, including java, pass array into function as reference (modifiable). But somehow it does not work here, and the testArray is still 1,2,3 with size of 3. Strange enough,...
user avatar
40 votes
4 answers
94k views

Possible Duplicate: Is Java pass-by-reference? Does a List object get passed by reference? In other words, if I pass an ArrayList (java.util.ArrayList) object to a class, will it be automatically ...
Kirill Kulakov's user avatar
24 votes
11 answers
70k views

public class program1{ public static void main(String args[]){ java.util.Vector vc=new java.util.Vector(); vc.add("111"); vc.add("222"); functioncall(vc); ...
user617597's user avatar
13 votes
9 answers
8k views

I do not understand why System.out.println(name) outputs Sam without being affected by the method's concat function, while System.out.println(names) outputs Sam4 as a result of the method's append ...
Helenesh's user avatar
  • 4,399
12 votes
7 answers
15k views

I have the following code: public class Book { private static int sample1(int i) { return i++; } private static int sample2(int j) { return ++j; } public static ...
misguided's user avatar
  • 3,809
27 votes
5 answers
8k views

public class StackOverFlow { public static void main(String[] args) { ArrayList<String> al = new ArrayList<String>(); al.add("A"); al.add("B"); ...
Naresh's user avatar
  • 313
18 votes
6 answers
23k views

When I write like this: public class test { void mainx() { int fyeah[] = {2, 3, 4}; smth(fyeah); System.out.println("x"+fyeah[0]); } void smth(int[] fyeah) ...
good_evening's user avatar
  • 21.9k
13 votes
8 answers
38k views

I have studied that java is pass by reference but when I execute following code the strings are not swapped in main method why? static void swap(String s1, String s2){ String temp = s1; s1=s2;...
sabu's user avatar
  • 2,117
14 votes
5 answers
53k views

Beginner java question, but I cannot understand how call-by-Value ( or Reference ) is working in the example below - How come the String value is not modified after it exits the method while my ...
Anand Hemmige's user avatar
14 votes
4 answers
82k views

I have a question about changing the values of variables in methods in Java. This is my code: public class Test { public static void funk(int a, int[] b) { b[0] = b[0] * 2; a = ...
user42155's user avatar
  • 49.7k
14 votes
4 answers
49k views

i have done the following sample with to check my knowledge import java.util.Map; public class HashMap { public static Map<String, String> useDifferentMap(Map<String, String> ...
Joe's user avatar
  • 4,552

15 30 50 per page
1
2 3 4 5
131