Skip to content

Instantly share code, notes, and snippets.

View anderson-martins's full-sized avatar

anderson-martins anderson-martins

View GitHub Profile
Careful use of concurrency is particularly important to the Swing programmer. A well-written Swing program uses concurrency to create a user interface that never "freezes" — the program is always responsive to user interaction, no matter what it's doing. To create a responsive program, the programmer must learn how the Swing framework employs threads.
@anderson-martins
anderson-martins / listaDiretorio.java
Created August 16, 2012 17:28
Lista arquivos, pastas e subpastas de um diretorio
public static java.util.List<FileItem> listDirectoryAppend(File dir, java.util.List<FileItem> lista) {
if (dir.isDirectory()) {
String[] filhos = dir.list();
for (int i = 0; i < filhos.length; i++) {
File nome = new File(dir, filhos[i]);
if (nome.isFile()) {
if (nome.getName().toUpperCase().endsWith(".GBK")) {
lista.add(new FileItem(nome));
}
} else if (nome.isDirectory()) {
@anderson-martins
anderson-martins / iteration over HashTable.java
Created August 16, 2012 14:17
Iteration over HashTable
Map<Integer, String> map = ...
Iterator<Map.Entry<Integer, String>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Integer, String> entry = it.next();
// Remove entry if key is null or equals 0.
if (entry.getKey() == null || entry.getKey() == 0) {
it.remove();
@anderson-martins
anderson-martins / replace ignore case.java
Created August 14, 2012 17:30
String replace ignore case
String target = "FOOBar";
target = target.replaceAll("(?i)foo", "");
System.out.println(target);