This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes arrayCopy method on String array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "arrayCopy method on String array" Watch "arrayCopy method on String array" New topic
Author

arrayCopy method on String array

Krishnaveni Hanuman
Greenhorn

Joined: Feb 18, 2013
Posts: 10
Hi,
I am trying to perform an arrayCopy using a String array, but am getting the following error message. Can someone help me figure out what is the error?

ArrayCopyDemo.java:6: cannot find symbol
symbol : method arrayCopy(java.lang.String[],int,java.lang.String[],int,int)
location: class java.lang.System
System.arrayCopy(s2,0,s1,1,s2.length);


Code :

class ArrayCopyDemo {
public static void main(String [] args) {
String [] s1={"Hello","Hai","Hi","Bonjour","Namaste"};
String [] s2={"Good morning","Shubhodayam","Shubhodaya"};

System.arrayCopy(s2,0,s1,1,s2.length);
System.out.println("");

for(String str:s1) {
System.out.println(str);
}
}
}
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18507
    
  40

Krishnaveni Hanuman wrote:Hi,
I am trying to perform an arrayCopy using a String array, but am getting the following error message. Can someone help me figure out what is the error?

ArrayCopyDemo.java:6: cannot find symbol
symbol : method arrayCopy(java.lang.String[],int,java.lang.String[],int,int)
location: class java.lang.System
System.arrayCopy(s2,0,s1,1,s2.length);


Code :





The message is pretty clear. It is saying that there is no such a thing as an arrayCopy() method of the System class, that takes those five parameters.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4341
    
    7

Have a closer look at the method you think you're using. I think it's fair to say that this is an example of Java's core library breaking its own naming conventions. I wasn't surprised to see this method dates back to Java 1.0 - there were a few dodgy decisions made early on that are difficult to fix without breaking backwards compatibility.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7501
    
  18

Henry Wong wrote:The message is pretty clear. It is saying that there is no such a thing as an arrayCopy() method of the System class, that takes those five parameters.

@Krishnaveni: And you know what? I'd probably have run into that one too if I still compiled from the command line (which is good practise; don't get me wrong), because it's an old method that doesn't follow Sun's own "camel-case" guidelines.

The main lesson here: When you get a message like that, look at the docs carefully (character by character, if you have to), because Henry's quite right: the message tells you exactly what's wrong.

Winston

[Edit] Too late.

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

.... because it's an old method that doesn't follow Sun's own "camel-case" guidelines.


Why is it so? Can't it be rectified to System.arrayCopy(....)? Or is the impact on dependent classes simply overwhelming?


~ Mansukh
Krishnaveni Hanuman
Greenhorn

Joined: Feb 18, 2013
Posts: 10
Thank you all
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4341
    
    7

Mansukhdeep Thind wrote:Why is it so? Can't it be rectified to System.arrayCopy(....)? Or is the impact on dependent classes simply overwhelming?

Changing it would break any code that already uses it - and since it's been there since the beginning that's potentially a lot of code - and an unknown amount.

What they could do is mark arraycopy as deprecated, and introduce a new arrayCopy method that does the same thing (you'd probably change arraycopy to just call arrayCopy). That would be safe. But the question is whether it's worth it and whether it will just cause more confusion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: arrayCopy method on String array
 
Similar Threads
Problem in binarySearch()
subString
java program to password protect a signed pdf file
var args problem
:rolling: Innovative functions !!!