user109513: 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?

user13866: 
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 "uncooked" 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 "distributed" 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 "replicated" than "distributed". 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 "distributed".

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


user109511: At its core, a blockchain is a linked list with a twist.
In a normal linked list, each item points to the previous item (these are the "links" which allow us to traverse back through the list.) In a computer, these links are references to memory locations, but in a blockchain, they are references to the hashes of preceding blocks.
Most importantly, the block of data that is hashed to produce a blockhash includes within it the blockhash of the previous block. You can't change the previous blockhash inside of the current block without changing the hash of the current block... and this means you obviously can't replace a block in the chain without visibly breaking the chain of blockhashes that come after.
This is the critical difference between a linked list (or ArrayList) and a blockchain:

in a linked list, it's easy to replace any element by modifying two
elements, it and the element after it, and the change is not visible
in later parts of the chain
in a blockchain, to replace a single
element, you must replace all elements after it, corrupting the whole
chain in an obvious visible way

Now, in most blockchain implementation, including bitcoin, what I said above pertains only to block headers, not to whole data blocks. For efficiency, the block headers comprise the cryptographically chained list, and the data is stored in separate chunks. So how are they related?
Each block header also includes within it a hash of one data block. This way, if you're looking at block 2045 of data and want to authenticate it, you merely have to hash it and see if that hash matches the hash in block header 2045. Nobody can give you a false block of data without corrupting the hash and, as noted above, they can't change the hash in the header without corrupting the whole chain of headers.
That's the typically used blockchain structure:

A chain of block headers, each of which includes the hash of the
preceding block and also includes the hash of one data block.
A matching collection of data blocks, each of which has a hash that is
included in one of the block headers.

(You could dispense with the block header/data block separation, but it can make lots of things more efficient to separate them.)
If you have the first block (sometimes called a "genesis block") and the validation rules (including what hashes are used and how they made), you can validate everything else yourself, without having to trust some other system to give you honest data.
If designing your own blockchain, you obviously have a lot of leeway as to what goes into the data blocks, how they are stored and distributed, etc.  The choice of networking and storage protocols are not what make it a blockchain.
So, back to your original question: what is a block? It's just a chunk of data.
How is it stored? However you like, but for Bitcoin, they are just chunks of data disseminated via a P2P network of nodes, and many nodes will store those chunks in a database on disk. In fact, there are several bitcoin implementations which store them in different ways! But they can all agree on what's valid, because of the blockchain.

109513: <p>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?</p>
 13866: <blockquote>
<p><strong>How is data in a blockchain stored</strong></p>
</blockquote>
<p>So far as I know, the Bitcoin specifications do not mandate any particular structures for <em>storing</em> the Bitcoin transaction-journal (blockchain) in persistent storage (e.g. Hard disk).</p>
<p>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).</p>
<p>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.</p>
<blockquote>
<p><strong>Are blockchains just ArrayLists</strong></p>
</blockquote>
<p>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.</p>
<p>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.</p>
<blockquote>
<p><strong>maybe they are stored in some files that are distributed among a P2P network?</strong></p>
</blockquote>
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>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;.</p>
<hr />
<p>See also descriptions of Bitcoin Core's storage format in these answers:</p>
<ul>
<li><a href="https://bitcoin.stackexchange.com/a/11108/13866">What is the database for?</a></li>
<li><a href="https://bitcoin.stackexchange.com/a/29418/13866">What are the keys used in the blockchain levelDB</a></li>
</ul>
 109511: <p>At its core, a blockchain is a linked list with a twist.</p>
<p>In a normal linked list, each item points to the previous item (these are the &quot;links&quot; which allow us to traverse back through the list.) In a computer, these links are references to memory locations, but in a blockchain, they are references to the hashes of preceding blocks.</p>
<p>Most importantly, the block of data that is hashed to produce a blockhash <em>includes within it</em> the blockhash of the previous block. You can't change the previous blockhash <em>inside of</em> the current block without changing <em>the hash of</em> the current block... and this means you obviously can't replace a block in the chain without visibly breaking the chain of blockhashes that come after.</p>
<p>This is the critical difference between a linked list (or ArrayList) and a blockchain:</p>
<ul>
<li>in a linked list, it's easy to replace any element by modifying two
elements, it and the element after it, and the change is not visible
in later parts of the chain</li>
<li>in a blockchain, to replace a single
element, you must replace all elements after it, corrupting the whole
chain in an obvious visible way</li>
</ul>
<p>Now, in most blockchain implementation, including bitcoin, what I said above pertains only to block headers, not to whole data blocks. For efficiency, the block headers comprise the cryptographically chained list, and the data is stored in separate chunks. So how are they related?</p>
<p>Each block header also includes within it a hash of one data block. This way, if you're looking at block 2045 of data and want to authenticate it, you merely have to hash it and see if that hash matches the hash in block header 2045. Nobody can give you a false block of data without corrupting the hash and, as noted above, they can't change the hash in the header without corrupting the whole chain of headers.</p>
<p>That's the typically used blockchain structure:</p>
<ol>
<li>A chain of block headers, each of which includes the hash of the
preceding block and also includes the hash of one data block.</li>
<li>A matching collection of data blocks, each of which has a hash that is
included in one of the block headers.</li>
</ol>
<p>(You could dispense with the block header/data block separation, but it can make lots of things more efficient to separate them.)</p>
<p>If you have the first block (sometimes called a &quot;genesis block&quot;) and the validation rules (including what hashes are used and how they made), you can validate everything else yourself, without having to trust some other system to give you honest data.</p>
<p>If designing your own blockchain, you obviously have a lot of leeway as to what goes into the data blocks, how they are stored and distributed, etc.  The choice of networking and storage protocols are not what make it a blockchain.</p>
<p>So, back to your original question: what is a block? It's just a chunk of data.</p>
<p>How is it stored? However you like, but for Bitcoin, they are just chunks of data disseminated via a P2P network of nodes, and many nodes will store those chunks in a database on disk. In fact, there are several bitcoin implementations which store them in different ways! But they can all agree on what's valid, because of the blockchain.</p>
