JAVA-8354: Split or move core-java-collections-3

This commit is contained in:
sampadawagde
2021-12-05 11:58:14 +05:30
parent ec85ef689f
commit 78828b8989
6 changed files with 19 additions and 14 deletions

View File

@@ -11,7 +11,7 @@
- [Performance of contains() in a HashSet vs ArrayList](https://www.baeldung.com/java-hashset-arraylist-contains-performance)
- [Fail-Safe Iterator vs Fail-Fast Iterator](https://www.baeldung.com/java-fail-safe-vs-fail-fast-iterator)
- [Quick Guide to the Java Stack](https://www.baeldung.com/java-stack)
- [Convert an Array of Primitives to a List](https://www.baeldung.com/java-primitive-array-to-list)
- [A Guide to BitSet in Java](https://www.baeldung.com/java-bitset)
- [Get the First Key and Value From a HashMap](https://www.baeldung.com/java-hashmap-get-first-entry)
- [Performance of removeAll() in a HashSet](https://www.baeldung.com/java-hashset-removeall-performance)
- More articles: [[<-- prev]](/core-java-modules/core-java-collections-2) [[next -->]](/core-java-modules/core-java-collections-4)

View File

@@ -1,47 +0,0 @@
package com.baeldung.collections.iterators;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import com.google.common.primitives.Ints;
import org.apache.commons.lang3.ArrayUtils;
public class ConvertPrimitivesArrayToList {
public static void failConvert() {
int[] input = new int[]{1,2,3,4};
// List<Integer> inputAsList = Arrays.asList(input);
}
public static List<Integer> iterateConvert(int[] input) {
List<Integer> output = new ArrayList<Integer>();
for (int value : input) {
output.add(value);
}
return output;
}
public static List<Integer> streamConvert(int[] input) {
List<Integer> output = Arrays.stream(input).boxed().collect(Collectors.toList());
return output;
}
public static List<Integer> streamConvertIntStream(int[] input) {
List<Integer> output = IntStream.of(input).boxed().collect(Collectors.toList());
return output;
}
public static List<Integer> guavaConvert(int[] input) {
List<Integer> output = Ints.asList(input);
return output;
}
public static List<Integer> apacheCommonConvert(int[] input) {
Integer[] outputBoxed = ArrayUtils.toObject(input);
List<Integer> output = Arrays.asList(outputBoxed);
return output;
}
}

View File

@@ -1,38 +0,0 @@
package com.baeldung.collections.iterators;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
import com.google.common.primitives.Ints;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ConvertPrimitivesArrayToListUnitTest {
@Test
public void givenArrayWithPrimitives_whenIterativeConvert_thenArrayGetsConverted() {
assertEquals(Arrays.asList(1,2,3,4), ConvertPrimitivesArrayToList.iterateConvert(new int[]{1,2,3,4}));
}
@Test
public void givenArrayWithPrimitives_whenStreamConvert_thenArrayGetsConverted() {
assertEquals(Arrays.asList(1,2,3,4), ConvertPrimitivesArrayToList.streamConvert(new int[]{1,2,3,4}));
}
@Test
public void givenArrayWithPrimitives_whenIntStreamConvert_thenArrayGetsConverted() {
assertEquals(Arrays.asList(1,2,3,4), ConvertPrimitivesArrayToList.streamConvertIntStream(new int[]{1,2,3,4}));
}
@Test
public void givenArrayWithPrimitives_whenGuavaConvert_thenArrayGetsConverted() {
assertEquals(Arrays.asList(1,2,3,4), ConvertPrimitivesArrayToList.guavaConvert(new int[]{1,2,3,4}));
}
@Test
public void givenArrayWithPrimitives_whenApacheCommonConvert_thenArrayGetsConverted() {
assertEquals(Arrays.asList(1,2,3,4), ConvertPrimitivesArrayToList.apacheCommonConvert(new int[]{1,2,3,4}));
}
}

View File

@@ -1,4 +1,4 @@
package com.baeldung.stack;
package com.baeldung.collections.stack;
import org.junit.Test;