Is there way for port forwarding to AWS MongoDB cluster

Can anybody please provide guidance on how to write java code for port forwarding for command below?

ssh -N -i xxxxxxxx-us-east-1.pem -L 27018:dbcluster-xxxxxxxxx.us-east-1.docdb.amazonaws.com:27018 ec2xxxxxxx@ec2.compute-1.amazonaws.com.

I want to connect with mongodb but before that I need to do port forwarding. Whenever I have to connect with mongodb. I have to run the command in command line, then I can connect with db via java code.

I want to do port forwarding via code as well. Thanks.