Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another question regarding arrays

 
Ben Buchli
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

is

int[] newArray = arrayReferencePassedAsMethodParameter.clone();

equals to copying the returned array into a new array? I mean, do I make sure that I dont refer to the reference that could be modified somewhere else?

Thanks in advance,
Ben
 
Hari Gangadharan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep. It is safe as long as it is an array of primitive datatypes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic