Created
October 5, 2010 05:24
-
-
Save lfborjas/611043 to your computer and use it in GitHub Desktop.
Ejemplos del 5 de octubre de 2010
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
package ejercicios; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
public class Conjuntos{ | |
private static ArrayList<String> union1(ArrayList<String> primero, ArrayList<String> segundo){ | |
ArrayList<String> retVal = new ArrayList<String>(primero); | |
for(String worte: segundo){ | |
if(!primero.contains(worte)) | |
retVal.add(worte); | |
} | |
return retVal; | |
} | |
private static ArrayList<String> union2(ArrayList<String> primero, ArrayList<String> segundo){ | |
ArrayList<String> retVal = new ArrayList<String>(primero); | |
retVal.addAll(segundo); | |
//Aquí falta algo... | |
return retVal; | |
} | |
public static void main(String[] args){ | |
ArrayList<String> primero = new ArrayList(Arrays.asList(args[0].split(","))); | |
ArrayList<String> segundo = new ArrayList(Arrays.asList(args[1].split(","))); | |
System.out.printf("Con el primer método: \n El primero: %s\n El segundo: %s\n La unión: %s\n", primero, segundo, union1(primero, segundo)); | |
System.out.printf("Con el segundo método (que no funciona...): \n El primero: %s\n El segundo: %s\n La unión: %s\n", primero, segundo, union2(primero, segundo)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
git://gist.github.com/611133.git