title: how to get the first or (any) element from a LiveData List in Android MVVM architecture?
body: <p>I used MVVM architecture to build an Android application with a Repository as a mediation between the <code>ViewModel</code> and Room database. In one of the functions, I retrieve a list of objects from a table in the repository class so that I can call it from the <code>ViewModel</code> class.</p>
  <p><strong>how to retrieve the first element in the list from the repository class instead of observing the <code>LiveData</code> in any one of the activities?</strong></p>
  <p>Here is my repository class:</p>
  <pre><code>public class StudentRepository {
  
      private StudentDAO mStudentDAO;
      private LiveData&lt;List&lt;Student&gt;&gt; mAllStudents;
   
      public StudentRepository(Application application){
          StudentRoomDatabase db = StudentRoomDatabase.getDatabase(application);
          mStudentDAO= db.StudentDAO();
          mAllStudents= mStudentDAO.getAllStudents();
      }
  
  
     
      public LiveData&lt;List&lt;Word&gt;&gt; getAllStudents(){
   
          // What I need to return the first element in the mAllStudents list
          // in order to type the first student name in the Log.d 
         
   **Log.d(&quot;First_Name&quot;,mAllStudent.get(0));
  // I want to type the student name in the Log without adding a function in
  the viewModel and observe that in any Activity**
  
          return mAllStudents;
      }
  
  }
  </code></pre>