The question you asked has a straightforward answer: the potential difference across the two capacitors must be equal, so the charges distribute in inverse proportion to the capacitances.
$$V_1 = V_2 \implies \frac{Q_1}{C_1} = \frac{Q_2}{C_2}$$
where $Q_1 + Q_2$ is your total charge.
I wanted to highlight a more subtle point though, concerning the energy of the system.
Consider two capacitors of the same size, with one initially charged to $V_i$, and the other initially uncharged. They are connected end to end via a switch (see diagram).
From what has been said, we expect the charge, $Q = CV_i$ on the first capacitor to distribute itself evenly between the two capacitors because they have the same capacitance.
Therefore the final voltage over each capacitor will be the same and correspond to holding a charge of $\frac{1}{2}Q$. This is $V = Q/C = \frac{1}{2}Q/C = \frac{1}{2}V_i$.
But what has happened to the energy? It was initially just $\frac{1}{2}V^2/C$ but it is now $2 \times \frac{1}{2}(V/2)^2/C = \frac{1}{4}V^2/C$.
So the energy has halved. What? Where has the other half gone? There is no resistance, so no energy can be dissipated, yet it is clearly halved.
This problem might trip you up and indeed there is a Wikipedia page titled "Two capacitor paradox", that explains this in detail.
Source: https://en.wikipedia.org/wiki/Two_capacitor_paradox
The solution is that, in reality, our circuit is not ideal. We have assumed the wires in the circuit has zero resistance and inductance. If this really were the case, the current would be infinite when the switch was closed due to a potential difference with zero resistance!
If we were to just introduce resistance, we would see that the current in the circuit when the switch is flipped would decay exponentially to reach the steady state solution we found above (equal charge distribution. This is an RC circuit. In the process half the initial energy would be lost.
And if we introduced inductance, then we would have an LC circuit and thus perpetual oscillation of charge between the two capacitors. Here no energy would be lost - when the charge is distributed evenly between the two capacitors, the remaining half of the energy will be stored in the magnetic field of the inductor.
In reality there would be both inductance and resistance in the wires, so we would have an RLC circuit. In this case the steady state would eventually be reached again, but instead of exponentially decaying, as in an RC circuit, the current would take the form of an exponentially decaying sinusoidal wave (well depending on the relative values of R and L, it might just decay without any oscillation anyway, in the so-called "over damped" case).