• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

arrayCopy method on String array

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}
}
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic