Skip to content

Instantly share code, notes, and snippets.

@lq920320
Created July 24, 2018 03:37
Show Gist options
  • Save lq920320/14d21844525b1e2a12c79aec2b2300a5 to your computer and use it in GitHub Desktop.
Save lq920320/14d21844525b1e2a12c79aec2b2300a5 to your computer and use it in GitHub Desktop.
List<String> to String[] by Lambda
/**
* @author liuqian
* @date 2018/7/2 17:42
*/
public class StringTest {
@Test
public void heh() {
List<Employee> employees = new ArrayList<Employee>() {{
add(new Employee() {{
setUserId("A01");
}});
add(new Employee() {{
setUserId("A02");
}});
add(new Employee() {{
setUserId("A03");
}});
add(new Employee() {{
setUserId("A04");
}});
add(new Employee() {{
setUserId("A05");
}});
add(new Employee() {{
setUserId("A06");
}});
}};
String[] userArray = employees.stream().map(Employee::getUserId).toArray(String[]::new);
System.out.println(Arrays.toString(userArray));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment