• Post Reply Bookmark Topic Watch Topic
  • New Topic

Copying array into another array  RSS feed

 
Ayukawa Madoka
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

/* Program name: Array02.java
* Author name: Place your name here
* Description:
*/

// Class name
public class Array02 {
// Main function
public static void main ( String[] args ) {
int items[] = {4,5,0,7};
int hold[] = {6,2,1,8,5};
System.out.println(items,0,hold,0,items.length);
}
}

I wrote a program based on my study guide that copy a data from items[0] and paste it into hold[0] which will replace the data in hold[0]
But it gaves an error during the compilation. Can anyone help me to fix this thanks.
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see it anyway that you are trying to copy and paste. Besides, println method doesn't support what you trying to do anyway. This should give you a basic example.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will you please post the exact error message that you recieve? Copy and paste it word for word so we don't have to guess what the problem is. Also, as Adrian mentioned, the code you posted doesn't even match the description you gave. I don't see any code that is trying to copy from one array to another. The System.out.println() method prints text to the standard output (typically the monitor or console). To copy from one array element to another, you should use something like this:
hold[0] = items[0];
I still think you need to reword your question, or explain what you mean a little better. I hope we can help you out once you do this. And remember to post the exact compiler error that you get!
Layne
 
Ayukawa Madoka
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry my english is poor. let me explain again, the method above is a method that copy the data in an array named items[0] which is 10 and stored it into another array named hold[0] which would overwrite the value of 20. thus the value in hold[0] became 10.
my reference book doesnt explain much. that is all it explain. i'm a bit confused so i need help from you guys.
here's the output:
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ayukawa-
I think this is what you are trying to do

[ March 06, 2004: Message edited by: Vicken Karaoghlanian ]
 
Ayukawa Madoka
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hold[0] = items[0];


System.arraycopy(items,0,hold,0,items.length);

Yes this is what i want! yay thanks a lot guys!!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!