How do i calculate prediction probability of a class in Java Weka Api?
Welcome to the community!
You can replace your code by the following code.

double[] prediction=classifier.distributionForInstance(instance);

    for (int k&lt;prediction.length; k++){
    System.out.println("Probability of class "+
      trains.classAttribute().value(k)+
       " : "+Double.toString(prediction[k]));
      }


This loop prints all the four values.
Hope it will help you.