I have the following List:
private String[] myArray = new String[]{"A","B","C"} ;
List myList = new ArrayList();
for (int i = 0; i < myArray.length; i++) {
myList.add(myArray[i]);
}
There is a method that returns an element of the myList
String returnValue=myMethod();
returnValue could be A or B or C
returnValue should be the first element of the List
myList.add(0, returnValue);
Issue is if returnValue="B" ,myList becomes {"B","B","C"}.
I could explicitly remove the returnValue and add it again to myList. But it seems rather redundant ,can anybody suggest a better design approach.
My Required Result would be {"B","A","C"}