Skip to content

Instantly share code, notes, and snippets.

@ejknapp
Created February 7, 2014 02:10
Show Gist options
  • Save ejknapp/8856327 to your computer and use it in GitHub Desktop.
Save ejknapp/8856327 to your computer and use it in GitHub Desktop.
Set demo from week 4
package java112.labs1;
import java.io.*;
import java.util.*;
/**
* @author Eric Knapp
* class SetDemo
* TODO: comment
*/
public class SetDemo {
public void run() {
Set<String> set = new TreeSet<String>();
set.add("Three");
set.add("One");
set.add("Four");
set.add("Two");
set.add("Four");
set.add("Four");
set.add("Four");
set.add("Four");
set.add("Four");
set.add("Four");
System.out.println(set);
for (Iterator iterator = set.iterator(); iterator.hasNext(); ) {
String element = (String)iterator.next();
System.out.println(element);
}
System.out.println();
for (String element : set) {
System.out.println(element);
}
}
public static void main(String[] args) {
SetDemo demo = new SetDemo();
demo.run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment