[JAVA] Add empty data to the top of the list

This time, I didn't know how to add empty data to the list data obtained from the DB base, so I investigated various things, so I will leave it as a memo. There may be other easier ways, so I'd be happy if a kind person could tell me.

    //Add empty data to the top of the list
	public static <T> List<T> addEmptyItem(List<T> list, Class<T> clazz) throws Exception {
		list.add(0, clazz.getDeclaredConstructor().newInstance());
		return list;
	}

Recommended Posts

Add empty data to the top of the list
[Java] How to add data to List (add, addAll)
How to sort the List of SelectItem
[Rails] Button to return to the top of the page
How to delete / update the list field of OneToMany
4 Add println to the interpreter
How to add elements without specifying the length of the array
[Rails] How to display the list of posts by category
Add Extended Attributes to the file
[Java] Delete the elements of List
Filter the fluctuations of raw data
Official logo list of the service
How to add the delete function
Method to add the number of years and get the end of the month
Display text on top of the image
How to determine the number of parallels
I wanted to add @VisibleForTesting to the method
How to change the maximum and maximum number of POST data in Spark
List of recommended articles related to Corda
What is the data structure of ActionText?
[Rails 6] cocoon_ Add id and data attributes to the form to be added
Output of the book "Introduction to Java"
The process of introducing Vuetify to Rails
Ability to display a list of products
The contents of the data saved by CarrierWave.
Add arbitrary parameters to the URL output by <h: outputScript> <h: outputStylesheet> of JSF
How to make a unique combination of data in the rails intermediate table
[No.004] Corrected the order list screen of the orderer
[Order method] Set the order of data in Rails
How to find the cause of the Ruby error
I want to output the day of the week
Customize how to divide the contents of Recyclerview
Add the JDK to the TeamCity build agent container
Make a margin to the left of the TextField
Ominous odor list suggesting the possibility of refactoring
The story of introducing Ajax communication to ruby
Set the time of LocalDateTime to a specific time
How to add sound in the app (swift)
The story of raising Spring Boot 1.5 series to 2.1 series
I want to var_dump the contents of the intent
How to get today's day of the week
Change the timezone of the https-portal container to JST
Output of how to use the slice method
[Ruby] Code to display the day of the week
Add classpath: to the path specified in spring.datasource.schema
The story of adding the latest Node.js to DockerFile
How to display the result of form input
[Java] How to get the authority of the folder
Java Welcome to the Swamp of 2D Arrays
[Swift] Use Swity JSON to easily get information from JSON data of the fortune-telling API
[Introduction to Java] List of things that got caught by the 14th day of programming
[Java] How to get the URL of the transition source
ArrayList and the role of the interface seen from List
List the contents of categories created with Active Hash
When the hover of Eclipse is hard to see
Extend Highfaces to flip the vertical axis of the graph
How to write Scala from the perspective of Java
I was addicted to the record of the associated model
I tried to summarize the state transition of docker
I saw the list view of Android development collectively
Touch Glassfish 6 to commemorate the release of Jakarta EE 9