• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

arrayCopy method on String array

 
Krishnaveni Hanuman
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9497
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.... 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?
 
Krishnaveni Hanuman
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic