java - How to return Arrays.asList() in ordered list<String>? -
i don't know duplicate or not. if so, please share link don't find yet. in java program, have string following(string created dynamically).
string header="requirements id,requirements number,requirements desc,requirements text,requirements date";
now creating list
list<string> csv = new arraylist<string>(); csv=arrays.aslist(header.split("\\s*,\\s*")); //splittng each phrase separated comma
but not getting list value in unordered way. mean list value this
[requirements number,requirements date,requirements desc,requirements id,requirements text]
i know list unordered. want list csv this
[requirements id,requirements number,requirements desc,requirements text,requirements date]
so question how in ordered way? possible solution?
the best way use stringtokenizer
1.) using stringtokenizer, split string delimiter ","
2.) iterate stringtokenizer , fill list
3.) while filling, happen in order
pseudo code like
string header="requirements id,requirements number,requirements desc,requirements text,requirements date"; stringtokenizer st = new stringtokenizer(header,",") ; list<string> strlist = new arraylist<string>() ; while (st.hasnexttoken()) { strlist.add(st.nexttoken()) ; }