Created
December 27, 2013 02:24
-
-
Save wjn/8141683 to your computer and use it in GitHub Desktop.
Append: This class appends array list a to array list b thus creating array list c.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Arrays; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
public class Append { | |
public static void main(String[] args) | |
{ | |
Scanner in = new Scanner(System.in); | |
ArrayList<Integer> a = new ArrayList<Integer>(); | |
ArrayList<Integer> b = new ArrayList<Integer>(); | |
ArrayList<Integer> c = new ArrayList<Integer>(); | |
System.out.println("Enter a series of integers separated by spaces: "); | |
while(in.hasNextInt()) | |
{ | |
a.add(in.nextInt()); | |
} | |
System.out.println("Enter another series of integers separated by spaces: "); | |
while(in.hasNextInt()) | |
{ | |
b.add(in.nextInt()); | |
} | |
in.close(); | |
System.out.print("\nArrayList a: "); | |
for(Integer i : a) | |
{ | |
System.out.print(i + " "); | |
} | |
System.out.print("\nArrayList b: "); | |
for(Integer i : b) | |
{ | |
System.out.print(i + " "); | |
} | |
c = appendArrayList(a,b); | |
System.out.print("\nArrayList c: "); | |
for(Integer i : c) | |
{ | |
System.out.print(i + " "); | |
} | |
} | |
public static ArrayList<Integer> appendArrayList(ArrayList<Integer> a, ArrayList<Integer> b) | |
{ | |
for(Integer i : b) | |
{ | |
a.add(i); | |
} | |
return a; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment