title: Converting from List of Object to List of String using streams
body: <p>I recently started working in Java streams. I was trying to get the String values out of the result set of one of my SQL queries. The result set selects just a String/Varchar column from the DB.</p>
  
  <p>So I did:</p>
  
  <pre><code>List&lt;String&gt; list = query.getResultList().stream().map(Object::toString).collect(Collectors.toList());
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>List&lt;String&gt; list =  = query.getResultList().stream().map(String::valueOf).collect(Collectors.toList());
  </code></pre>
  
  <p>I believe the map takes a function to convert data from one type to another. In this case, from Object to String and then collect them in a String list.</p>
  
  <p>But the above code shows compile time error: Cannot convert from Object to List of string.</p>
  
  <p>Please suggest me the correct way of doing this and explain what is wrong with my understanding.</p>