Last active
December 30, 2015 08:49
-
-
Save olupotd/7804692 to your computer and use it in GitHub Desktop.
A much simpler version of the Whole Application. Data structures
This file contains 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
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import org.apache.commons.lang3.ArrayUtils; | |
/* | |
NB You shall need the org.apache.commons library installed on your system. | |
Get it from here or run this http://github.com/olupotd/installApache.sh script | |
like this if you are using Linux. | |
wget -c http://mirror.ucu.ac.ug/apache//commons/lang/binaries/commons-lang3-3.1-bin.tar.gz && tar -zxvf commons-lang3-3.1-bin.tar.gz | |
Go to your project properties and add it to them or just paste the jar files in your libs files in the Java Folder. | |
Good luck Assuming you already have eclipse installed. | |
*/ | |
public class Simple { | |
//declared an array of | |
Object[] orderedList = {20,45,51,78,84,91,98}; | |
int[] elems = {10,15,77,92,200}; | |
List<Integer> list = new ArrayList<Integer>(); | |
Object[] addElement(Object[] orderedList2, int added) { | |
Object[] result = Arrays.copyOf(orderedList2, orderedList2.length +1); | |
result[orderedList2.length] = added; | |
return result; | |
} | |
public Simple() { | |
for(int i = 0; i < elems.length; i++) | |
orderedList = addElement(orderedList, elems[i]); | |
Arrays.sort(orderedList); | |
viewList(orderedList); | |
System.out.println("Removed Elements 45 and 91"); | |
orderedList =(Object[])ArrayUtils.removeElement(orderedList, 91); | |
orderedList =(Object[])ArrayUtils.removeElement(orderedList, 45); | |
viewList(orderedList); | |
} | |
private void viewList(Object[] orderedList2) { | |
for(int x = 0; x<orderedList2.length; x++) | |
{ | |
System.out.println(orderedList2[x]+""); | |
} | |
} | |
public static void main(String[] args) { | |
new Simple(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment