How to arrange the datas to display in array by given string of days in java?

Collections.rotate will do that you want

String[] daysArr = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
List<String> daysList = Arrays.asList(daysArr);
String input = "Fri";
int index = daysList.indexOf(input);
if (index > 0) {
    Collections.rotate(daysList, -index);
}
System.out.println(daysList);

Hope it helps!

Browse More Popular Posts

Leave a Comment