Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7972867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:57:55+00:00 2026-06-04T07:57:55+00:00

I currently have an ArrayList filled with dates in the format 2012-06-19 and I

  • 0

I currently have an ArrayList filled with dates in the format 2012-06-19 and I am trying to add them all to an array of Dates.

This is the portion of code that is failing me,

    listIterator = dateValues.listIterator();

    Date [] dates = new Date[dateValues.size()];
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    int i = 0;
    try{
        while(listIterator.hasNext())
        {
            //System.out.println(listIterator.next().toString());
            dates[i] =  dateFormat.parse(listIterator.next().toString());
            i++;

        }

        for(i = 0; i < dates.length;i++)
        {
            System.out.println(dates[i]);
        }
    }
    catch(Exception e){e.printStackTrace()};
}

The line

//System.out.println(listIterator.next().toString());

will print out every date in the ArrayList. Output looks like,

2007-09-07
2007-09-07
2007-10-05
2007-10-05
2007-10-05
2007-10-05
2007-10-05

but my dateFormat line never adds any values to dates[]. Any help would be appreciated.

And no, it isn’t homework.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:57:57+00:00Added an answer on June 4, 2026 at 7:57 am

    Try this:

    List<String> dateValues = new ArrayList<String>();
    Date[] dates = new Date[dateValues.size()];
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    int i = 0;
    for (String dateValue : dateValues) {
        dates[i++] = dateFormat.parse(dateValue);
    }
    

    “Less code is good”, so use the language (foreach loops etc) to keep your code small and clean (like the code above).

    Note to pedants before you comment: “less code is good”, as long as it remains readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have an arraylist containing classes in C#. The arraylist is filled like
I currently have an arraylist in which I add blossom objects ( which fall
Currently I have my code putting user input into a one-dimensional ArrayList, but I
Currently in my JQuery script I have a hard coded array: var arrayList =
We currently have a specific format for how our email addresses are defined, based
I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
I currently have the dynamic array: char *myData[500][10]; //myData is the name of an
Using VB.NET (3.5), i have an ArrayList of Employees. I'm trying to build an
I currently have an ArrayList of strings in Java, but I would like to
I need to write an arraylist to a file. It gets filled all the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.