How to add a user in the roster?

How does a user A add another user B in his roster, so that both the users are able to chat to each other when they are online ?

While looking at the documentation,I checked out the RosterGroup class and its method addEntry.

This is what I was trying :

RosterEntry re;

re.setName("B");

RosterGroup rg;

rg.addEntry(re);

I don’t know how to initialize the constructor of both the RosterEntry and RosterGroup class. And is this the way to add a user in roster ?