The Buddha explains how he divided his thoughts into two kinds - 1) thoughts of sensual desire, ill-will, and harm; and 2) thoughts of relinquishment, non-ill-will, and non-harm. He explains how he abandoned harmful thoughts and cultivated wholesome thoughts, leading to the attainment of the four jhānas and the three knowledges.
Dvedhāvitakka sutta - The Two Kinds of Thoughts
Thus have I heard — At one time, the Blessed One was dwelling in Sāvatthi, in Jeta's Grove, Anāthapiṇḍika's park. There, the Blessed One addressed the bhikkhus thus: "Bhikkhus".
"Venerable sir", those bhikkhus responded to the Blessed One. The Blessed One said this:
"Before my enlightenment, when I was still an unenlightened bodhisatta, it occurred to me, 'What if I divided my thoughts into two kinds?' Thus, bhikkhus, I made one part consist of the thoughts of sensual desire, thoughts of ill-will, and thoughts of harm; and the other part consist of the thoughts of relinquishment, thoughts of good-will, and thoughts of non-harm.
Unwholesome Thoughts
Sensual Desire
As I dwelled diligently, with continuous effort, and resolutely, a thought of sensual desire arose in me, bhikkhus. I then understood: 'This thought of sensual desire has arisen. It leads to self-harm, to others' harm, and to the harm of both. It obstructs wisdom, is afflictive, and is not conducive to Nibbāna.' Reflecting in this way, bhikkhus, that 'It leads to self-harm,' it subsided in me; 'It leads to others' harm,' it subsided in me; 'It leads to the harm of both,' it subsided in me; 'It obstructs wisdom, is afflictive, and not conducive to Nibbāna,' it also subsided in me. Therefore, bhikkhus, whenever a thought of sensual desire arose, I immediately abandoned it, removed it, and completely eradicated it.
Ill-will
As I dwelled diligently, with continuous effort, and resolutely, bhikkhus, a thought of ill-will arose in me. I then understood: 'This thought of ill-will has arisen. It leads to self-harm, to others' harm, and to the harm of both. It obstructs wisdom, is afflictive, and is not conducive to Nibbāna.' Reflecting in this way, bhikkhus, that 'It leads to self-harm,' it subsided in me; 'It leads to others' harm,' it subsided in me; 'It leads to the harm of both,' it subsided in me; 'It obstructs wisdom, is afflictive, and not conducive to Nibbāna,' also it subsided in me. Therefore, bhikkhus, whenever a thought of ill-will arose, I immediately abandoned it, removed it, and completely eradicated it.
Harm
As I dwelled diligently, with continuous effort, and resolutely, bhikkhus, a thought of harm arose in me. I then understood: 'This thought of harm has arisen. It leads to self-harm, to others' harm, and to the harm of both. It obstructs wisdom, is afflictive, and is not conducive to Nibbāna.' Reflecting in this way, bhikkhus, that 'It leads to self-harm,' it subsided in me; 'It leads to others' harm,' it subsided in me; 'It leads to the harm of both,' it subsided in me; 'It obstructs wisdom, is afflictive, and not conducive to Nibbāna,' also it subsided in me. Therefore, bhikkhus, whenever a thought of harm arose, I immediately abandoned it, removed it, and completely eradicated it.
Whatever a bhikkhu frequently thinks about and ponders upon, bhikkhus, that will become the inclination of his mind. If a bhikkhu frequently thinks about and ponders upon thoughts of sensual desire, he abandons thoughts of relinquishment, makes thoughts of sensual desire predominant, and his mind inclines towards those thoughts of sensual desire. Similarly, if he frequently engages with thoughts of ill-will and harming, he abandons thoughts of good-will and non-harming, makes thoughts of ill-will and harming predominant, and his mind inclines towards those thoughts of ill-will and harming.
Just as, bhikkhus, in the last month of the rainy season, during the harvest season when the fields are crowded with crops, a cowherd would guard his cows. He would strike the cows here and there with a stick, push them back, restrain them, and hold them together. For what reason? Bhikkhus, the cowherd sees the danger that might arise from those causes: beating, confinement, seizure, or reproach.
Similarly, bhikkhus, I saw in unwholesome mental qualities the danger, baseness and defilement, and in wholesome mental qualities the benefit, relinquishment, and purification.
Wholesome Thoughts
Relinquishment
As I dwelled diligently, with continuous effort, and resolutely, a thought of relinquishment arose in me, bhikkhus. I then understood: 'This thought of relinquishment has arisen. It leads neither to self-harm, nor to others' harm, nor to the harm of both. It cultivates wisdom, is not afflictive, and is conducive to Nibbāna.' If, bhikkhus, I were to dwell upon and examine this thought by night, I would see no danger arising from it. If I were to dwell upon and examine it by day, I would see no danger arising from it. And even if I were to dwell upon and examine it by night and day, I would see no danger arising from it. However, if I were to dwell on and examine it for too long, my body would become tired. When the body is tired, the mind becomes disturbed, and a disturbed mind is far from being settled. Therefore, bhikkhus, I stabilized my mind internally, settled it, unified it, and composed it. For what reason? So that my mind might not become disturbed.
Good-will
As I dwelled diligently, with continuous effort, and resolutely, a thought of good-will arose in me, bhikkhus. I then understood: 'This thought of good-will has arisen. It leads neither to self-harm, nor to others' harm, nor to the harm of both. It cultivates wisdom, is not afflictive, and is conducive to Nibbāna.' If, bhikkhus, I were to dwell upon and examine this thought by night, I would see no danger arising from it. If I were to dwell upon and examine it by day, I would see no danger arising from it. And even if I were to dwell upon and examine it by night and day, I would see no danger arising from it. However, if I were to dwell on and examine it for too long, my body would become tired. When the body is tired, the mind becomes disturbed, and a disturbed mind is far from being settled. Therefore, bhikkhus, I stabilized my mind internally, settled it, unified it, and composed it. For what reason? So that my mind might not become disturbed.
Non-harm
As I dwelled diligently, with continuous effort, and resolutely, a thought of non-harm arose in me, bhikkhus. I then understood: 'This thought of non-harm has arisen. It leads neither to self-harm, nor to others' harm, nor to the harm of both. It cultivates wisdom, is not afflictive, and is conducive to Nibbāna.' If, bhikkhus, I were to dwell upon and examine this thought by night, I would see no danger arising from it. If I were to dwell upon and examine it by day, I would see no danger arising from it. And even if I were to dwell upon and examine it by night and day, I would see no danger arising from it. However, if I were to dwell on and examine it for too long, my body would become tired. When the body is tired, the mind becomes disturbed, and a disturbed mind is far from being settled. Therefore, bhikkhus, I stabilized my mind internally, settled it, unified it, and composed it. For what reason? So that my mind might not become disturbed.
Whatever a bhikkhu frequently thinks about and ponders upon, bhikkhus, that will become the inclination of his mind. If a bhikkhu frequently thinks and ponders upon thoughts of relinquishment, he abandons thoughts of sensual desire, makes thoughts of relinquishment predominant, and his mind inclines towards those thoughts of relinquishment. Similarly, if a bhikkhu frequently thinks and ponders upon thoughts of good-will and non-harming, he abandons thoughts of ill-will and thoughts of harm, makes thoughts of good-will and non-harm predominant, and his mind inclines towards those thoughts of good-will and non-harming.
Just as in the last month of the hot season, when all the crops have been brought in from the fields, a cowherd would watch over the cows, and whether he is sitting at the root of a tree or out in the open, he only needs to be mindful that the cows are there. In the same way, bhikkhus, I only needed to be mindful that those wholesome mental qualities were there.
The Four Jhānas
Bhikkhus, unrelenting energy was aroused [in me], clear and unmuddled mindfulness was established, the body was tranquil and unexcited, and the mind was collected and unified.
Thus, bhikkhus, having secluded myself from sensual pleasures and unwholesome mental qualities, I entered and dwelled in the first jhāna, which is accompanied by reflection and examination, born from seclusion, and is filled with joyful pleasure.
With the settling of reflection and examination, I entered and dwelled in the second jhāna, which is characterized by internal tranquility and unification of mind, is without reflection and examination, born from collectedness, and is filled with joyful pleasure.
With the fading away of joyful pleasure, I dwelled in a state of equanimity, mindful and fully aware, experiencing ease with the body. I entered and dwelled in the third jhāna which the Noble Ones describe as 'one who dwells equanimous, mindful and at ease.'
With the abandonment of ease and discontentment, and with the settling down of joy and sorrow, I entered and dwelled in the fourth jhāna, which is characterized by purification of mindfulness through equanimity, experiencing neither-painful-nor-pleasant sensation.
The Three True Knowledges
Thus, with my mind collected, purified, clarified, blemish-free, free from impurities, flexible, suitable for use, stable, and unshakable, I directed my mind towards the knowledge of recalling past lives. I recollected my manifold past lives, including details and brief descriptions of each life.
In the first watch of the night, bhikkhus, I attained the first knowledge: ignorance was dispelled, knowledge arose, darkness was dispelled, and light arose, as occurs for one who is diligent, with continuous effort, and resolute in practice.
Thus, with my mind collected, purified, clarified, blemish-free, free from impurities, flexible, suitable for use, stable, and unshakable, I directed my mind toward the knowledge of the death and rebirth of beings. With the divine eye, purified and surpassing the human, I saw beings passing away and reappearing, endowed with bodily misconduct and other misdeeds, in various states, fair and foul, fortunate and unfortunate, and I understood them according to their actions.
In the middle watch of the night, I attained the second knowledge: once more, ignorance was dispelled, knowledge arose, darkness was dispelled, and light arose, reflecting the state of one who is diligent, with continuous effort, and resolute in practice.
Thus, with my mind collected, purified, clarified, blemish-free, free from impurities, flexible, suitable for use, stable, and unshakable, I directed my mind towards the knowledge of eradicating the taints. I directly knew as it actually is: 'This is suffering,' 'This is the origin of suffering,' 'This is the ending of suffering,' 'This is the way leading to the ending of suffering.'
'I know these taints,' I directly knew as it actually is, 'This is the origin of these taints,' I directly knew as it actually is, 'This is the cessation of these taints,' I directly knew as it actually is, 'This is the way leading to the cessation of these taints,' I directly knew as it actually is. Knowing and seeing thus, my mind was liberated from the taint of sensual desire, from the taint of being, and from the taint of ignorance. In me, liberated, there arose the knowledge of liberation: 'Birth is ended, the spiritual life has been lived, what had to be done has been done, there is no more coming to any state of being.'
This, bhikkhus, was the third knowledge attained by me in the last watch of the night; ignorance was dispelled, knowledge arose, darkness was dispelled, and light arose, as happens in one who dwells diligently, with continuous effort, and with resolution.
Suppose, bhikkhus, in a wooded range there is a great low-lying marsh near which a large herd of deer resides. A man appears, desiring their ruin, harm, and bondage, and closes off the safe and good path to be joyfully traveled, opens a false path, and sets out a decoy and a dummy, leading the herd towards calamity, disaster, and loss. Yet another man appears, desiring their good, welfare, and protection. He reopens the safe and good path leading to their happiness, closes off the false path, removes the decoy, and destroys the dummy, enabling the herd to achieve growth, increase, and fulfillment.
Bhikkhus, I have given this simile in order to convey a meaning. This is the meaning: 'The great low-lying marsh' is a term for sensual pleasures. 'The large herd of deer' represents beings. 'The man desiring their ruin, harm, and bondage' is a term for Māra the Evil One. 'The false path' represents the wrong eightfold path - wrong view, wrong intention, wrong speech, wrong action, wrong livelihood, wrong effort, wrong mindfulness, and wrong collectedness. 'The decoy' is a term for delight and lust. 'The dummy' is a term for ignorance. 'The man desiring their good, welfare, and protection' is a term for the Tathāgata, the accomplished and fully enlightened one. 'The safe and good path to be traveled joyfully' is a term for the Noble Eightfold Path - right view, right intention, right speech, right action, right livelihood, right effort, right mindfulness, and right collectedness.
So, bhikkhus, the safe and good path to be traveled joyfully has been re-opened by me, the wrong path has been closed off, the decoy removed, and the dummy destroyed.
What a teacher should do out of compassion for his disciples, seeking their welfare, I have done for you, bhikkhus. Here are these roots of trees, here are these empty huts. Meditate, bhikkhus, do not be negligent; lest you later regret it. This is our instruction to you."
The Blessed One said this. The bhikkhus were satisfied and rejoiced in the Blessed One's words.