How is data in a blockchain stored? Structure of block and blockchain I'm trying to build a blockchain-based application and I have a problem with understanding some crucial issues.
What exactly is a block? I mean, I've seen application where blocks were just String structures and a blockchain was an ArrayList of these String structures. But my question is, does it work like that in real blockchains? Are blockchains just ArrayLists or maybe they are stored in some files that are distributed among a P2P network?
How is data in a blockchain stored

So far as I know, the Bitcoin specifications do not mandate any particular structures for storing the Bitcoin transaction-journal (blockchain) in persistent storage (e.g. Hard disk).
Any Bitcoin node is free to store the transaction-journal in whatever form is convenient. For example it might be decomposed as a set of tables in third-normal form in a relational database in &quot;uncooked&quot; storage outside any filesystem. The node might include in the stored data a complex set of indices for fast retrieval of certain types of data (e.g. Bitcoin-addresses).
Bitcoin Core stores the transaction-journal in groups of consecutive blocks in a series of large files whose format I believe closely matches the form used in the Bitcoin network protocols. But there is no prohibition on other software products doing something quite different.

Are blockchains just ArrayLists

That is just one way of representing the data. Note that the ArrayList is a feature of specific programming languages. It may not exist in some languages and quite different data structures may be more appropriate in that case.
The data itself needs to keep track of blocks and those blocks contain data that references data within other blocks. Hence the name. But there are many different ways of implementing these ideas which could all work in a Bitcoin node.

maybe they are stored in some files that are distributed among a P2P network?

Normally, in my field of work, the term &quot;distributed&quot; implies that not all nodes hold all the data. It implies that there is some planned and coordinated division of data among nodes so that specific nodes are designated to be responsible for specific subsets. This isn't really a fundamental design feature of Bitcoin.
I believe that initially Bitcoin used a model that I would more strongly associate with the word &quot;replicated&quot; than &quot;distributed&quot;. Initially all nodes each had a full and complete copy of the entire data-set. There was no system to coordinate the intentional distribution of subsets of data among cooperating storage nodes.
Currently nodes, even full nodes, can discard blocks that are no longer of interest to them. This means that many nodes do not contain a complete set of data. Importantly however, any distribution of the data between nodes is essentially unplanned and uncoordinated.
You could argue that there is distribution of data between SPV clients and the servers they rely on for transaction-journal data. However I'm moderately sure this isn't really the sort of distribution of data that database engineers generally mean when they use the term &quot;distributed&quot;.

See also descriptions of Bitcoin Core's storage format in these answers:

What is the database for?
What are the keys used in the blockchain levelDB