Skip to content

Instantly share code, notes, and snippets.

@tonysm
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save tonysm/1861cb37bfdca2d1eecd to your computer and use it in GitHub Desktop.

Select an option

Save tonysm/1861cb37bfdca2d1eecd to your computer and use it in GitHub Desktop.
JavaCollections - exemplo
import java.util.ArrayList;
import java.util.Collection;
public class Main {
public static void main(String[] args) {
Collection<String> nomes = new ArrayList<String>();
nomes.add("Primeiro nome digitado");
nomes.add("Segundo nome");
for (String nome:nomes) {
System.out.println("Nome: " + nome);
}
System.out.println("Total de clients: " + nomes.size());
}
}
import java.util.List;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
List<String> nomes = new ArrayList<String>();
List<String> emails = new ArrayList<String>();
nomes.add("Primeiro nome digitado");
emails.add("primeiro@example.com");
nomes.add("Segundo nome");
emails.add("segundo@example.com");
for (int i = 0; i < nomes.size(); i++)
{
System.out.println("Cliente: " + nomes.get(i));
System.out.println("Email: " + emails.get(i));
}
System.out.println("Total de clients: " + nomes.size());
}
}
/**
* output:
*
* Cliente: Primeiro nome digitado
* Email: primeiro@example.com
* Cliente: Segundo nome
* Email: segundo@example.com
* Total de clients: 2
*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment