Mon Oct 22, 2012 8:51 pm
import java.util.SortedSet;
import java.util.TreeSet;
public class ArraysWork {
public static void main(String[] arr) {
SortedSet<String> stringsTreeSet = new TreeSet<String>();
stringsTreeSet.add("keen");
stringsTreeSet.add("adjust");
stringsTreeSet.add("zip");
stringsTreeSet.add("diagnosis");
stringsTreeSet.add("claim");
stringsTreeSet.add("play");
// Printing the content of the Tree set
// Notice that the strings are ordered alphabetically
System.out.println("---------------------------------");
System.out.println("Elements in Tree set : " + stringsTreeSet);
/*
* Show first element
*/
System.out.println("---------------------------------");
System.out.println("Element at first:"+stringsTreeSet.first());
System.out.println("---------------------------------");
/*
Copy to array of string...
*/
Object[] strArray = stringsTreeSet.toArray();
/* All elements of array... */
for (int i = 0; i < strArray.length; i++) {
System.out.println("Array element : " + strArray[i]);
}
}
---------------------------------
Elements in Tree set : [adjust, claim, diagnosis, keen, play, zip]
---------------------------------
Element at first:adjust
---------------------------------
Array element : adjust
Array element : claim
Array element : diagnosis
Array element : keen
Array element : play
Array element : zip
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.