Total members 11893 |It is currently Fri Nov 15, 2024 8:09 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Convert the content of ordered Tree set into a normal java array.
Code:


import java
.util.SortedSet;
import java.util.TreeSet;

public class 
ArraysWork {

    public static 
void main(String[] arr) {
        
SortedSet<StringstringsTreeSet = 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 0strArray.lengthi++) {

            
System.out.println("Array element : " strArray[i]);
        }

    }
 


The output is:
Code:
---------------------------------
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




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Convert TreeSet content to array
 Convert normal array to a list     -  
 Array difference for associate array     -  
 show the content of set     -  
 Hide the content of the div     -  
 compare an array with another array?     -  
 check folder content using asp     -  
 lowercase table content     -  
 Read the content from directory     -  
 Web content & Website Design     -  
 usage of the meta tag for content encoding     -  



Topic Tags

Java Collections
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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