Write code to convert string splitted by space To Set
//package com.book2s; import java.util.Arrays; import java.util.HashSet; import java.util.Set; public class Main { public static void main(String[] argv) { String string = "b o o k 2 s.com"; System.out.println(stringToSet(string)); }//from w w w . java 2 s . co m public static Set<String> stringToSet(String string) { Set<String> res = new HashSet<String>(); if (string != null && !string.equals("")) { res.addAll(Arrays.asList(string.split(" "))); } return res; } }