Problem with assigning an array to other array in Java

public class TestingArray { public static void main(String[] args) { int iCheck = 10; int j = iCheck; j = 11; System.err.println("value of iCheck "+iCheck); int[] val1 = {1,2,9,4,5,6,7}; int[] val2 = val1; val2[0] = 200; System.err.println("Array Value "+val1[0]); } } Output: > **value of iCheck 10 > Array Value 200** From the above code, I found that if any array `val2` is being assigned to another array `val1` and if we change any value of `val2` array, the result is as well reflected for the array `val1` while the same scenario is not with variable assignment. Why?

以上就是Problem with assigning an array to other array in Java的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准