Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Comparing Strings

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    56
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Comparing Strings

    If I wanted to take strings in from the user through a GUI say day, month, year. I am looking for a way to organize those incoming strings. I am going to add this information to a queue. However, I want the people who put in the earliest day, month, and year to be put into the queue first followed by the next earliest so on and so forth. Has anyone done anything like this before? I was thinking what I would need to make a method that would compare the information. Any clues on how I can do this is there a fairly straightforward method for doing this or no?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Comparing Strings

    If I wanted to take strings in from the user through a GUI say day, month, year. I am looking for a way to organize those incoming strings
    Parse the String into the appropriate class instance, for example with date/time information you could use DateFormat to parse into a Date
    DateFormat (Java Platform SE 7 )

    However, I want the people who put in the earliest day, month, and year to be put into the queue first followed by the next earliest so on and so forth.
    See PriorityQueue (Java Platform SE 7 )

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    56
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Comparing Strings

    Hey this is good thank you, however; I am still having issues. So I can get it to print like today's date:

    package testdates;
    import java.text.DateFormat;
    import java.util.Date;
     
    public class Testdates {
     
        public static void main(String[] args) {
            Date today = new Date();
     
            DateFormat fullDate = DateFormat.getDateInstance(DateFormat.FULL);
     
            System.out.println(fullDate.format(today));
        } 
    }

    but I am still confused about the parsing part. Does this class have a method that will compare incoming strings or something I missed in the DateFormat (Java Platform SE 7 )? Also, I have to use my own queue I am not allowed to use the java class queue but I already have a circular queue that I build earlier that is going to handle dequeuing and whatnot, would you like to see it?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Comparing Strings

    Does this class have a method that will compare incoming strings or something I missed in the DateFormat (Java Platform SE 7 )?
    The Date class implements the Comparable interface (see it's compareTo method), the DateFormat class is for formatting and parsing - I recommend studying the API for these classes if you intend to use them as the API can answer many of your questions.

    I have to use my own queue I am not allowed to use the java class queue but I already have a circular queue that I build earlier that is going to handle dequeuing and whatnot, would you like to see it?
    Do you have a question about this class in particular?

Similar Threads

  1. EASY [comparing two vectors of strings]
    By speaker in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 14th, 2012, 06:19 PM
  2. [SOLVED] Comparing Date Strings
    By wdh in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 26th, 2012, 03:28 AM
  3. Comparing a character to an array of strings
    By Hashmeer169 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 4th, 2011, 07:55 PM
  4. Comparing Strings?
    By wandertheverse in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 4th, 2011, 10:32 PM
  5. Comparing Strings only using the .length() method - possible?
    By Ryker in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 16th, 2010, 05:52 PM