Skip to content

Instantly share code, notes, and snippets.

@lfborjas
Created October 5, 2010 05:24
Show Gist options
  • Save lfborjas/611043 to your computer and use it in GitHub Desktop.
Save lfborjas/611043 to your computer and use it in GitHub Desktop.
Ejemplos del 5 de octubre de 2010
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));
}
}
@10851077
Copy link

10851077 commented Oct 5, 2010

git://gist.github.com/611133.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment