Set,list,array (collections and Arrays) in Java are converted to each other

Source: Internet
Author: User

Public Staticobject[] List2array (List<Object>Olist) {
object[] Oarray=Olist.toarray (Newobject[] {});
//TODO needs to write another method when it is used, and does not support the array of Generics.
Returnoarray;
}

Public Staticobject[] Set2array (Set<Object>Oset) {
object[] Oarray=Oset.toarray (Newobject[] {});
//TODO needs to write another method when it is used, and does not support the array of Generics.
Returnoarray;
}

Public Static <TExtendsObject>List<T>Set2list (Set<T>Oset) {
List<T>TList= NewArrayList<T>(oset);
//TODO needs to write another construct when it is used, and generate the corresponding subclass of the list as Needed.
ReturntList;
}

Public Static <TExtendsObject>List<T>Array2list (t[] Tarray) {
List<T>TList=Arrays.aslist (tarray);
//TODO Simple Aslist () The returned tlist cannot add (), remove (), clear () and other actions that affect the number of collections,
//Because Arrays$arraylist and java.util.ArrayList are the same, they inherit abstractlist,
//But Arrays$arraylist did not override these methods, and Java.util.ArrayList implemented Them.
//TODO recommends using the subclass of list to do the return instead of Arrays$arraylist. If you need it. Comments such as the Downlink:
//list<t> tList = new arraylist<t> (arrays.aslist (tarray));
ReturntList;
}

Public Static <TExtendsObject>Set<T>List2set (List<T>TList) {
Set<T>Tset= NewHashSet<T>(tList);
//TODO-specific implementations look at the need to convert a subclass of a different set.
Returntset;
}

Public Static <TExtendsObject>Set<t> Array2set (t[] Tarray) {
set<t> tset = new Hashset<t< Span style= "color: #000000;" >> // TODO There is no one step method, according to the specific function, select the appropriate set subclass to Convert.
return tset;
}
/span>

Set,list,array (collections and Arrays) in Java are converted to each other

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.