Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

convert list to array

807589Nov 14 2007 — edited Aug 27 2008
Hello, I have an array, I want to remove the duplicate items then create the new array whose elements are unique.
My code is incompleted.
Please give me a hint.
Thanks
 String[] authors={"a","b","c","a","b","d",....};
 List authorList = new ArrayList();
                        for(int k = 0; k<j; k++) {
                                authorList.add(authors[k]);
                        }
                       
                    
                        Set<String> set1 = new LinkedHashSet<String>(authorList); 
                        
                        List list = new ArrayList();
                        for(String s:set1){
                            list.add(s);
                        }
                        String [] authorlist = new String[list.size()];//new array
                        for(int i = 0;i<list.size();i++) {
                            authorlist[i] = list.toArray();//wrong here
                        }
                                            set1.clear();
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 24 2008
Added on Nov 14 2007
7 comments
627 views