Created
July 24, 2018 03:37
-
-
Save lq920320/14d21844525b1e2a12c79aec2b2300a5 to your computer and use it in GitHub Desktop.
List<String> to String[] by Lambda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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