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);



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. 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.

  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training India . Nowadays Java has tons of job opportunities on various vertical industry.