Saturday, 6 June 2015

How to convert array to TreeSet

import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;

public class ArrayToTreeSet {
   
    public static void main(String[] args) {
       
            String [] arr={"java","php","html","json","ajax"};
           
            for (String str : arr) {
                System.out.println("Array element is ="+str);
            }

            Set<String> ts = new TreeSet<String>(Arrays.asList(arr));
           
            // print treeset
           
            for (String str : ts) {
                System.out.println("TreeSet Element = "+str);
            }
       
        }

}

Output:

Array element is =java

Array element is =php

Array element is =html

Array element is =json

Array element is =ajax

TreeSet Element = ajax

TreeSet Element = html

TreeSet Element = java

TreeSet Element = json

TreeSet Element = php


Related Posts: 




1 comment:

  1. Great blog created by you. I read your blog, its best and useful information. You have done a great work. Super blogging and keep it up.
    php jobs in hyderabad.

    ReplyDelete