The code I wrote here works, but I am pretty sure it is awful and not so efficient. This function takes in input a list of strings which is splitted on comma and then each generated string is trimmed.
One example:
INPUT: [[Cat, Dog, Snake]]
OUTPUT: Cat Dog Snake
private List<String> splitListOfString(LinkedList<String> list)
{
String mylist = list.toString();
mylist = mylist.substring(2);
mylist = mylist.substring(0, mylist.length() - 2);
List<String> thelist = Arrays.asList(mylist.split(","));
List<String> thelist2 = new LinkedList<String>();
for (String string : thelist) {
thelist2.add(string.trim());
}
return thelist2;
}
How would you improve this code?
["[Cat", "Dog", "Snake]"](size 3) or["[Cat, Dog, Snake]"](size 1)? My guess is the latter, but ... why?toString()-d. You already have a list, so iterate over it,trim()the values,toStringcall on list is very confusing - so hard to say why it is there and if removal will actually make code easier for data you have.