jueves, 25 de abril de 2013
Combinar datos , eliminar Duplicados y Ordenarlos con List, HashSet y SortedSet JAVA
String[] arr = {"1", "2", "3", "3"};
List<String> lista1 = java.util.Arrays.asList(arr);
List<String> lista2 = java.util.Arrays.asList("8", "6", "5");
List<String> combinar = new ArrayList<String>();
combinar.addAll(lista1);
combinar.addAll(lista2);
for (String s : combinar) {
System.out.print(s + " ");
}
System.out.println();
HashSet duplicado = new HashSet();
duplicado.addAll(combinar);
Iterator iterador = duplicado.iterator();
while (iterador.hasNext()) {
String elemento = (String) iterador.next();
System.out.print(elemento + " ");
}
System.out.println();
SortedSet ordenado = new TreeSet();
ordenado.addAll(duplicado);
iterador = ordenado.iterator();
while (iterador.hasNext()) {
String elemento = String.valueOf(iterador.next());
System.out.print(elemento + " ");
}
System.out.println();
Salida:
1 2 3 3 8 6 5
3 2 1 6 5 8
1 2 3 5 6 8
Saludos!!
Armando Mateu
lunes, 15 de abril de 2013
Applet + MySQL ... Usar un Applet y Conectar a MySQL
Usar un Applet y Conectar a MySQL
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import javax.swing.table.DefaultTableModel;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ahmateu
*/
public class Principal extends javax.swing.JApplet {
/**
* Initializes the applet Principal
*/
@Override
public void init() {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the applet */
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
Suscribirse a:
Entradas (Atom)