I have a Java list, I need to split the list based on the index values passed from a property file.
Example :
ArrayList<String> sampleList = new ArrayList<String>();
sampleList.add("1");
sampleList.add("2");
sampleList.add("3");
sampleList.add("4");
sampleList.add("5");
sampleList.add("6");
sampleList.add("7");
sampleList.add("8");
sampleList.add("9");
sampleList.add("10");
Let's say for the first time, the index passed from property file are 3,5. So my output should be
For example :
System.out.println(sampleList.subList(0,3)+" "+sampleList.get(3)+" "+sampleList.subList(4,5)+" "+sampleList.get(5)+" "+sampleList.subList(6,sampleList.size()));
[1,2,3] 4 [5] 6 [7,8,9,10]
Next time if the indexes passed are 3,5,8 and the output should be
[1,2,3] 4 [5] 6 [7,8] 9 [10]
I have tried to sublist the list and pass on the indexes manually. It does gives output but it's not efficient.
Please advice how this can be done dynamically.TIA
[1, 2, 3] 4 [5] 6 [7, 8, 9, 10]. Can you describe in words what the parameters 3 and 5 should do?