473,566 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copying array values in Java

sreekandank
45 New Member
Java allows you to copy the value of one array into another. It can be done by using the arraycopy method of System class. It can be used as the following form:
System.arraycop y(from, fromIndex, to, toIndex, count);
  • from - specifies the array name from which you want to copy.
  • fromIndex - specifies the position of the array from which you want to copy.
  • to - specifies the destination array name on which you want to store the values.
  • toIndex - specifies the position of the destination array from which you want to store the values.
  • count - specifies the number of elements that you want to copy and store.

The following example shows the array copying mechanism in Java.

ArrayCopyDemo.j ava
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. /**
  3. *@author Sreekandan.K
  4. */
  5. class ArrayCopyDemo
  6. {
  7.  public static void main(String args[])
  8.  {
  9.   int[] mark1={55,77,89,91,57};
  10.   int[] mark2={45,35,41,33,30,06};
  11.   System.out.println("The Elements of first array are:");
  12.   for(int i=0;i<mark1.length;i++)
  13.   {
  14.    System.out.println(mark1[i]);
  15.   }
  16.   System.out.println("The Elements of second array are:");
  17.   for(int i=0;i<mark2.length;i++)
  18.   {
  19.    System.out.println(mark2[i]);
  20.   }
  21.   System.arraycopy(mark1,2,mark2,3,3);
  22.   System.out.println("The Values in Second Array(mark2) after replacement are:");
  23.   for(int i=0;i<mark2.length;i++)
  24.   {
  25.    System.out.println(mark2[i]);
  26.   }
  27.  }
  28. }
Author : Sreekandan.K
Attached Images
File Type: jpg Output.jpg (42.2 KB, 471 views)
Nov 6 '11 #1
0 4111

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2333
by: EdInPhoenix | last post by:
I'm not sure where to post this, so I thought I'd start here. I need to get a .NET web service to play nice with a Java consumer. The web service passes back a byte array with an encrypted string. The java app needs to decrypt the bytes. The problem I think is that .net bytes can be 0-255, but Java bytes are -127-128. How can we get java...
7
11049
by: Oleg Konovalov | last post by:
Hi, I am trying to pass a bunch of checked checkboxes (Javascript array) from page1 to the Java action class on subsequent web page (page2). (on page 1 I have a bunch of DB rows with a checkbox, need to iterate through pages page2 - e.g. allow user to update the fields there) On page1 I have a bunch of checkboxes with the same name v1...
5
3277
by: Victor Bazarov | last post by:
Below you will find some code I wrote to see if I could wrap array copying (especially for multi-dimensional arrays) in a simple class and/or function. It seems to work fine for one-dimensioned arrays as well as two-dimensioned ones. I am sure three- or more-dimensioned array are just as OK here. My concern was that I couldn't use...
4
1963
by: ankurmaheshwari | last post by:
hii all How to make 2-d array in java when no of rows are not known let me know if u have the solution 4 it... Regards ankur maheshwari
1
4826
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of algorithm, initialization vector (IV), mode, padding, key etc, but I just don't get the two languages to "understand each other", or, in other words,...
2
17943
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of algorithm, initialization vector (IV), mode, padding, key etc, but I just don't get the two languages to "understand each other", or, in other words,...
0
3552
by: Miraj Godha | last post by:
Hi , I want to send array from java program to postgre. For oracle we can achieve it by using: ArrayDescriptor desc = ArrayDescriptor.createDescriptor("TYPE", conn); ARRAY newArray = new ARRAY(desc, conn, attributeData); pstmt.setArray(10,newArray);
0
4080
by: anuptosh | last post by:
Hi, I have been trying to run the below example to get a Oracle Array as an output from a Java code. This is an example I have found on the web. But, the expected result is that the code should return me Array element type code 1, but it is returning me type code 12 and the array in a junk or unreadable format . Our environment is JDK 1.4,...
4
11593
shashankraj1231
by: shashankraj1231 | last post by:
I am trying to write a Java program in which we would take input from the user until the user enters -1. The input would be integers and has to be stored in a integer array. I am a newbie in Java and i am trying to self study here. Please tell me what am i doing wrong. It would be of great help. class storearray{ public static void...
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.