In: Computer Science
Given two String arrays (named below), write the code that you would need in order to copy the data from relatives into weddingInvitations in java.
1. relatives (which is loaded with data)
2. weddingInvitations (that is the same size as relatives)
CODE -
public class copy
{
public static void main(String[] args)
{
// Declaring and initializing the string array "relatives"
String[] relatives = new String[]{"Vision", "Hawk Eye", "Black Widow", "Winter Soldier", "Captain America", "Iron Man", "Thor", "Hulk"};
// Finding the size of the string array "relatives"
int size = relatives.length;
// Declaring the string array "weddingInvitations" with same size as "relatives"
String[] weddingInvitations = new String[size];
// Iterating oveer the string array "relatives"
for(int i=0; i<size; i++)
// Copying the data from the string array "relatives" into the string array "weddingInvitations"
weddingInvitations[i] = relatives[i];
// Displaying the string array "weddingInvitations"
for(int i=0; i<size; i++)
System.out.println(weddingInvitations[i]);
}
}
SCREENSHOT -
If you have any doubt regarding the solution, then do
comment.
Do upvote.