how to forward the calls to voice mail in android programmatically

The selected answer is only correct if you want to limit your implementation to the Android public SDK.

It is possible to send a call to voice mail programmatically on Android.

While the phone is ringing, end the call. The call will be diverted to voice mail by the network. In GSM/WCDMA this is a feature called User Determined User Busy or UDUB, it also works on CDMA devices.

There are plenty of answers on SO on how to end a call on Android:

Using Java reflection and the iTelephony interface:

End call in android programmatically or end incoming call programmatically

== Update 2020 ==

Since Android P it is possible to hangup calls using the Android SDK - therefore forwarding to voicemail is now a supported feature of Android.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
    TelecomManager tcm = context.getSystemService(TelecomManager.class);
    if(tcm != null)
        tcm.endCall();
}

Add the necessary permission to AndroidManifest.xml

    <uses-permission android:name="android.permission. ANSWER_PHONE_CALLS" />

You can't.

Call forwarding is done by your carrier not by your phone, when the call reaches your phone its too late to forward it.