Fragment object is just like other objects.Like String , you can invoke methods of string object, str.charAt(0) ,str.toUpperCase() etc. Just create a function in fragment, put your code there and call the function along with values
Inside Activity {
fragDemoObject.doWhatYouWant("this is passed as string object to fragment");
}
Inside FragmentDemo{
void doWhatYouWant(String input){
System.out.println(input);
// do what else you want to do with code
}
}