Firstly, both points in Answer by rzwitserloot are correct and wise:
- Forbidding the use of external libraries means missing out on the best reason to use Java: its vast and rich ecosystem of supporting libraries.
- Use the java.time classes such as
LocalDate for your work. Never use the legacy date-time class such as Date or Calendar.
Specifically, I suggest adding the ThreeTen-Extra library to make use of its LocalDateRange class to contain a pair of LocalDate objects. That class offers handy methods such as abuts, overlaps, contains, and so on.
I suggest you do all your date-handling by defining a span-of-time using the Half-Open approach where the beginning is inclusive while the ending is exclusive. So the month begins on the first and runs up to, but does not include, the first of the following months. June would be June 1 to July 1. The LocalDateRange uses Half-Open by default, but can also accommodate Fully-Closed (beginning and ending both inclusive) if you insist.
In Java 16 and later, use the records feature to define a class to hold your data transparently and immutably. You merely declare the type and name of each member field. The compiler implicitly creates the default constructor, getters, equals & hashCode, and toString. Bonus feature: a record can be defined locally in addition to nested or separately (ditto enum and interface).
So your entire class is one short line:
record CovidDaily ( String isoCode , String continent , String location, LocalDate date , … ) {}
To filter your rows, loop or use streams.
LocalDate start = LocalDate.of( 2021 , Month.JUNE , 1 ) ;
LocalDate end = LocalDate.of( 2021 , Month.JULY , 1 ) ;
List< CovidDaily > hits = new ArrayList<>() ;
List< CovidDaily > dailies = … ;
for( CovidDaily covidDaily: dailies )
{
LocalDate ld = covidDaily.date() ;
if( ( ! ld.isBefore( start ) ) && ( ld.isBefore( end ) )
{ hits.add( covidDaily) ; } // Else ignore this record and move on to next.
}
Generally best to return an unmodifiable result.
return List.copyOf( hits ) ;
Streaming approach is shorter.
LocalDate start = LocalDate.of( 2021 , Month.JUNE , 1 ) ;
LocalDate end = LocalDate.of( 2021 , Month.JULY , 1 ) ;
List< CovidDaily > dailies = … ;
return dailies.stream().filter( covidDaily -> ( ! covidDaily.date().isBefore( start ) ) && ( covidDaily.date().isBefore( end ) ) ).toList();
Using LocalDateRange.
LocalDateRange range = LocalDateRange.of(
LocalDate.of( 2021 , Month.JUNE , 1 ) ,
LocalDate.of( 2021 , Month.JULY , 1 ) ) ;
List< CovidDaily > dailies = … ;
return dailies.stream().filter( covidDaily -> range.contains( covidDaily.date() ) ).toList();