in my code
List<Student_Batch_Junction__c > c=new List<Student_Batch_Junction__c>([select Student__r.id from Student_Batch_Junction__c where Batch__r.Name in :b]);
variable c contains:
11:55:42:011 VARIABLE_ASSIGNMENT [11]|this.c|[{"Student__c":"a022v00001GmqnrAAB","Batch__c":"a042v00002CobkCAAR","Id":"a052v00000l4WxtAAE","Student__r":{"Id":"a022v00001GmqnrAAB"}},{"Student__c":"a022v00001GnNHiAAN","Batch__c":"a042v00002CobkCAAR","Id":"a052v00000l4c5dAAA","Student__r":{"Id":"a022v00001GnNHiAAN"}}]I want to get only Student__r id field values.how to get that?

Hi Agnibha, Please check below code:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.Thanks and Regards,Deepali Kulshresthawww.kdeepali.compublic class test {
public static void queryTest()
{
List<Batch__C> b= [Select Id,Name from Batch__C];
System.debug(b);
Set<Id> batchIds=new Set<Id>();
for(Course__c bs: b )
{
batchIds.add(bs.Id);
}
List<Student_Batch_Junction__c> c=new List<Student_Batch_Junction__c>([select Student__r.id from Student_Batch_Junction__c where Batch__r.Id in : batchIds]);
System.debug(c);
Set<Id> studIds=new Set<Id>();
for(Student_Batch_Junction__c sid:c)
{
studIds.add(sid.Student__r.Id);
}
System.debug(studIds);
}
}