Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Array  RSS feed

 
Siva kandasamy
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Look at the API document.
Arrays (Java 2 Platform SE v1.4.2)
I have two questions.
1. Why "arrycopy" function is defined in the System class instead of Array class.
2. Look at the "All classes" list in the API document.
I do see entry for class
- Array
- Array (in italic)
- Arrays
My questions is, what is that means here, meaning,
why Java desiger has to create so many Array class.
and What is the difference.
Thanks
siva
 
Howard Kushner
author
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Siva,
My answer to your first question, "Why should the System class be responsible for copying arrays?" is this. The copying of arrays is that type of utility functionality that might be needed anywhere. In my humble opinion, that type of behavior is well placed in the System class.
My short answer to your second question, "What are these classes, Array, Arrays, etc.?" is this: They are part of the Reflection API's, as well as providing other useful behavior specific to arrays. In particular, as you can see in the JavaDoc for the Arrays class (in the java.util package), it provides sorting and searching capabilities for arrays. The Array class (in the java.lang.reflect package) provides static (aka class) methods to create arrays dynamically, "on-the-fly" as needed.
Hope this helps.
Regards,
[ March 10, 2004: Message edited by: Howard Kushner ]
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) This is a bit of a guess, but I believe efficient array copying involves copying a block of memory from here to there, memory is handled in a system dependant way, thus, array copying is a system dependant operation.
2) The API gives further details than just the names of objects...
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The real answer to the first question is that java.lang.System has been part of the Java API since the very first release, and arraycopy() has always been located there; but java.util.Arrays wasn't added in JDK 1.2, several years later. Now, they could have added a copy() in Arrays, and deprecated System.arraycopy(), but they chose not to -- perhaps because then virtually every Java program in existence would be using a deprecated method!
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you click on the links for the names you listed, you will find out that Array (without italics) is a class in the java.lang.reflect package, Array (with italics) is an interface in the java.sql package, and Arrays is a class in the java.util package. The Java API gives plenty more details about when and how to use each of these.
Layne
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!