Skip to content

Instantly share code, notes, and snippets.

@walidum
Created May 23, 2021 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walidum/d09a69ff2e732799ec315037ef480f72 to your computer and use it in GitHub Desktop.
Save walidum/d09a69ff2e732799ec315037ef480f72 to your computer and use it in GitHub Desktop.
Collection to an Array
//Demo.java
public static String[] collectiontoArray() {
var sampleList = Arrays.asList("Algiers", "Setif");
return sampleList.toArray(String[]::new);
}
//DemoTest.java
@Test
public void collectiontoArrayTest() {
assertTrue(Arrays.equals(Demo.collectiontoArray(), new String[]{"Algiers", "Setif"}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment