package com.usr.collections;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class ReverseStringArray {
public static void main(String[] args) {
String[] strArr = { "sunday", "monday", "tuesday", "wednesday",
"thursday", "friday", "saturday" };
List<String> strList = Arrays.asList(strArr);
System.out.println("list objets before reverse are:");
System.out.println(strList);
System.out.println("...........................");
Collections.reverse(strList);
System.out.println("list objects after reverse are:");
System.out.println("..............................");
System.out.println(strList);
// convert to string array
strArr = strList.toArray(new String[strList.size()]);
System.out.println("...............................");
System.out.println("reversed string array elements are:");
System.out.println(".....................");
for (String temp : strArr) {
System.out.println(temp);
}
}
}
OUTPUT
list objets before reverse are:
[sunday, monday, tuesday, wednesday, thursday, friday, saturday]
...........................
list objects after reverse are:
..............................
[saturday, friday, thursday, wednesday, tuesday, monday, sunday]
...............................
reversed string array elements are:
.....................
saturday
friday
thursday
wednesday
tuesday
monday
sunday
OUTPUT
list objets before reverse are:
[sunday, monday, tuesday, wednesday, thursday, friday, saturday]
...........................
list objects after reverse are:
..............................
[saturday, friday, thursday, wednesday, tuesday, monday, sunday]
...............................
reversed string array elements are:
.....................
saturday
friday
thursday
wednesday
tuesday
monday
sunday
No comments:
Post a Comment
Note: only a member of this blog may post a comment.