How to find a list of temps for unique days?

record high and low temperatures by zip code
record high and low temperatures by city
daily temperature data by zip code
record high temperatures by date
daily high and low temperatures by city
daily record high and low temperatures by city
record temperatures for today
noaa weather data

I'm a student new to java and I'm having difficulty with the following problem. I have a massive String array of over 1 million weather readings, each element contains a Site ID, Site Name, Site latitude, Site Longitude, Year, Month, Date(1-31), Hour, Wind speed, Temperature.

My problem is: How many days did the temperature fall to or below 0.0 anywhere in the UK. All the entries are from the same year so that isn't a problem. But the month int variable goes ranges from 1 to 12 and the date int variable ranges from 1 to 31. What would be the best way to organise the data to allow me to only count unique days?

I've already created an object class called WeatherRecords with a get method that splits the strings up by the comma and parses each element into the correct type and stores the object in an array. Like so:

        String[] weatherData = WeatherData.getData();
        ArrayList<WeatherRecords> records = new ArrayList<>();
        for (int i = 1; i < weatherData.length; i++) {
            String line = weatherData[i];
            String[] elements = line.split(",");
            String siteIdString = elements[0];
            String siteName = elements[1];
            String siteLatString = elements[2];
            String siteLonString = elements[3];
            String recordYearString = elements[4];
            String recordMonthString = elements[5];
            String recordDateString = elements[6];
            String recordHourString = elements[7];
            String recordWindSpeedString = elements[8];
            String recordTempString = elements[9];
            int siteId = Integer.parseInt(siteIdString);
            double siteLat = Double.parseDouble(siteLatString);
            double siteLon = Double.parseDouble(siteLonString);
            int recordYear = Integer.parseInt(recordYearString);
            int recordMonth = Integer.parseInt(recordMonthString);
            int recordDate = Integer.parseInt(recordDateString);
            int recordHour = Integer.parseInt(recordHourString);
            int recordWindSpeed = Integer.parseInt(recordWindSpeedString);
            double recordTemp = Double.parseDouble(recordTempString);
            WeatherRecords record = new WeatherRecords(siteId, siteName, siteLat, siteLon, recordYear, recordMonth,
                    recordDate, recordHour, recordWindSpeed, recordTemp);
        return records;


Assuming Java 8 or more:

First, change your year, month day, hour to a LocalDateTime property of your WeatherRecord (I guess the class name should drop the "s"), it will be easier to handle.

Then, I should look into stream(), where you will be ablt to filter and retrieve what you need in your arrayList of WeatherRecord.

Heating & Cooling Degree Days, Heating degree days and cooling degree days for thousands of locations worldwide. You might also want to find out why 5,000+ energy professionals get data Degree will try to list the stations that it thinks can best represent Degree is not unique in having to deal with less-than- perfect temperature� Select a blank cell, for instance, B2, and type this formula =SUMPRODUCT(1/COUNTIF(A2:A22,A2:A22)) in to it, and press Enter, you can get the counting result. In above formula, A2:A22 is the range you want to count unique dates from, you can change it as you need. Count and color unique/duplicate dates in a column with Kutools for Excel.

Please try the code shown below. Use LocalDate to represent your year-month-day. Then use streams to filter and collect your targeted objects.

class WeatherRecord{
    double recordTemp;
    LocalDate localDate;
    String siteName;


WeatherRecord w1 = new WeatherRecord();
w1.setLocalDate(LocalDate.of(recordYear, recordMonth, recordDate));       

List<WeatherRecord> filteredList =
    .filter( w -> w.getRecordTemp() <= 0 )
    .collect( Collectors.toList() )

50 Degree Temperature Ranges, The high plains is in a unique region of the United States which sees some of the of to see temperature swings of 50 degrees or more within one calendar day. Find historical weather by searching for a city, zip code, or airport code. Include a date for which you would like to see weather history. You can select a range of dates in the results on the

How many days did the temperature fall to or below 0.0 anywhere in the UK

The very good Answer by dassum gets us most of the way, but omitted the part about getting to a list of distinct dates. Let's push that code a bit farther.

Our WeatherSample class is shown first.

Notice that we use BigDecimal rather than float or double or Float or Double, to avoid the inaccuracy of floating-point technology.

To compare a pair of BigDecimal objects, we cannot use the operators such as < or <=. We must call compareTo of the Comparable interface, which returns a negative integer if the first object is less than the second. So we can test for the result of compareTo being less than zero. See this Question for more info.

package work.basil.example;

        import java.math.BigDecimal;
        import java.time.LocalDate;
        import java.util.Objects;

final public class WeatherSample
    // ----------|  Member fields  |---------------------------
    final private LocalDate localDate;
    final private int hour;
    final private String siteName;
    final private BigDecimal recordTemp;

    // ----------|  Constructors  |---------------------------
    public WeatherSample ( LocalDate localDate , int hour , String siteName , BigDecimal recordTemp )
        this.localDate = Objects.requireNonNull( localDate );
        this.hour = Objects.requireNonNull( hour );
        this.siteName = Objects.requireNonNull( siteName );
        this.recordTemp = Objects.requireNonNull( recordTemp );  // Should also check for String::isBlank & String::isEmpty.

    // ----------|  Accessors  |---------------------------
    public LocalDate getLocalDate ( )
        return this.localDate;

    public int getHour ( )
        return this.hour;

    public String getSiteName ( )
        return this.siteName;

    public BigDecimal getRecordTemp ( )
        return this.recordTemp;

Make a few instances, and collect into a non-modifiable List. We have samples for the 23rd, 24th, and 25th. Only the first and last days are hits, having temps below zero.

List < WeatherSample > samples = List.of(
        new WeatherSample( LocalDate.of( 2020 , 1 , 23 ) , 11 , "Springfield" , new BigDecimal( "-23.5" ) ) ,
        new WeatherSample( LocalDate.of( 2020 , 1 , 23 ) , 13 , "Springfield" , new BigDecimal( "10.1" ) ) ,
        new WeatherSample( LocalDate.of( 2020 , 1 , 24 ) , 11 , "Springfield" , new BigDecimal( "4.5" ) ) ,
        new WeatherSample( LocalDate.of( 2020 , 1 , 24 ) , 13 , "Springfield" , new BigDecimal( "4.7" ) ) ,
        new WeatherSample( LocalDate.of( 2020 , 1 , 25 ) , 11 , "Springfield" , new BigDecimal( "-25.0" ) ) ,
        new WeatherSample( LocalDate.of( 2020 , 1 , 25 ) , 13 , "Springfield" , new BigDecimal( "-25.7" ) )

Code to process that list. First we generate a stream from our list, each WeatherSample object being considered in succession. Then we filter out the ones

List < LocalDate > dates =
                .filter( sample -> ( sample.getRecordTemp().compareTo( BigDecimal.ZERO ) < 0 ) )
                .map( sample -> sample.getLocalDate() )
                .collect( Collectors.toList() );

Dump to console.

System.out.println( "dates.toString(): " + dates );

When run.

dates.toString(): [2020-01-23, 2020-01-25]

You literally asked for just the number of days. Interrogate the List for its size.

int countOfDates = dates.size() ; 


Boise Climatology and Unique Local Data, Boise Climatology and Unique Local Data. Boise Airport Monthly Temperature Rankings Boise's Consecutive Days of 100 degrees or Warmer Having a list of days suchs as: 01-giu-16 01-giu-16 01-giu-16 31-mag-16 31-mag-16 31-mag-16 31-mag-16 30-mag-16 I was looking for an excel formula that helps me count the number of unique days in the list (in this example 3) Moreover I need the count only for the dates which have a specific ID in the next column (for example 1565)

Climate Change Indicators: Weather and Climate, Many extreme temperature conditions are becoming more common. Since the 1970s, unusually hot summer days (highs) have become more� Sorry for misleading description. My question is how many unique dates are in A1:A7 that are in the range between the dates, specified in C3 and D3. In this example I expect that formula give me number 2, because there are only 2 unique dates between Feb-01 and Mar-15 2016. – ggv Jun 19 '17 at 18:02

World of Change: Global Temperatures, The average global temperature has increased by a little more than 1� Celsius (2 � Fahrenheit) since 1880. Sea and Lake Ice � Severe Storms � Temperature Extremes � Unique Imagery � Volcanoes � Water Color The world is getting warmer. After all, temperatures fluctuate by many degrees every day where we live. There are a number of different ways to generate unique numbers in an InfoPath form. You could have the form query a SharePoint list for the max value of ID (each item in a SharePoint list is created with […]

Denver Colorado Weather & Temperature Info, Winters are mild with an average daily high temperature of 45 degrees Fahrenheit and days reaching 60 degrees are not uncommon. Snow doesn't stay on the� 1. Select a cells range (you’d better select much more cells than the dates you need to list). See screenshot: 2. Click Kutools > Insert > Insert Random Data. See screenshot: 3. In the Insert Random Data dialog, click Date tab, then type the start date in the From box, type the end date in the To box, and check Workday option and Unique

  • Is the input sorted on the date time columns? If so then you don't need to store them in a list.
  • Would be easier if the days, months and years were encapsulated in a LocalDate object in an instance of WeatherRecord (without the trailing s because it represents a single record).
  • most simple way would be to store this inside the WeatherRecords class if temperature is bellow 0.0 or equals it, then some method like getTotalBelowZeroDays and return this list size. or little bit prettier solution would be to use Comparator or comparable, sort data according the temperature and extract negative temparature count.
  • @GeorgeWeekson According to the description OP wants to count when the temp falls to or below 0, so its the change from positive to zero/negative that should be counted
  • @JoakimDanielson i understood and it can be easily counted while creating WeatherRecords object, because it carries recordTemp variable, it can be done with one variable inside the WeatherRecords every time temp fails to or below 0 increment variable, that's it. to evaluate and have more functionality OP can add that data to some container.
  • Please provide a proper solution, this is more suitable as a comment.
  • This helped me move in the correct direction. I altered my WeatherRecord Object to take in another variable at the end, which converted the year, month and date to a LocalDate variable using : LocalDate localDate = LocalDate.of(recordYear, recordMonth, recordDate); WeatherRecord record = new WeatherRecord(siteId, siteName, siteLat, siteLon, recordYear, recordMonth, recordDate, recordHour, recordWindSpeed, recordTemp, localDate); Cheers for the help guys.
  • @Conzo You might run into trouble if you are going to do this for over 1 million records