?
Solved

iterate among dates

Posted on 2005-04-09
3
Medium Priority
?
234 Views
Last Modified: 2010-03-31
Dear java experts ,
           
Another questions.
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a dd-MMM-yyyy");

Date Time1=sdf.parse(request.getParameter(time1).trim());
Date Time2=sdf.parse(request.getParameter(time2).trim());
Date Time3=sdf.parse(request.getParameter(time3).trim());
Date Time4=sdf.parse(request.getParameter(time4).trim());
Date Time5=sdf.parse(request.getParameter(time4).trim());

if i have  Date[] array with 5 elements. how  do i find which is the earliest date.


any help will be very highly apprecaiatted.
thanks,
testsubbu

0
Comment
Question by:Testsubbu
  • 2
3 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13745508
Arrays.sort(myarray);
Date earliest = myarray[0];
0
 
LVL 3

Accepted Solution

by:
neonlines earned 2000 total points
ID: 13746827
Just for shakeness, U can do sorting in the following ways :)


1.        // sorting by 'natural ordering'
        Arrays.sort(dateArray);


2.        // sorting by length
        Arrays.sort(dateArray, new Comparator()
            {
                public int compare(Object o1, Object o2)
                {
                    return (((String) o1).length() - ((String) o2).length());
                }
            });


3.        // sorting alphabetically
        Arrays.sort(dateArray, new Comparator()
            {
                public int compare(Object o1, Object o2)
                {
                    return (((String) o1).toLowerCase().
                            compareTo(((String) o2).toLowerCase()));
                }
            });


4.        // sorting by last letter
        Arrays.sort(dateArray, new Comparator()
            {
                public int compare(Object o1, Object o2)
                {
                    return(((String) o1).charAt(((String) o1).length() - 1) -
                           ((String) o2).charAt(((String) o2).length() - 1));
                }
            });


Very simple objects solution is quite enough ...

0
 
LVL 92

Expert Comment

by:objects
ID: 13749460
Thought you wanted to find the earliest???
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month16 days, 18 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question