primitive collections

This commit is contained in:
mherbaghinyan 2019-01-21 13:08:09 +04:00
parent c713ddee6d
commit 81f23992cb
1 changed files with 9 additions and 15 deletions

View File

@ -2,8 +2,6 @@ package com.baeldung.array;
import com.google.common.primitives.ImmutableIntArray; import com.google.common.primitives.ImmutableIntArray;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import gnu.trove.list.TIntList;
import gnu.trove.list.array.TIntArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -14,25 +12,21 @@ public class PrimitiveCollections {
int[] primitives = new int[] {5, 10, 0, 2}; int[] primitives = new int[] {5, 10, 0, 2};
//guavaPrimitives(primitives); guavaPrimitives(primitives);
trovePrimitives(primitives);
} }
private static void trovePrimitives(int[] primitives) {
TIntList tList = new TIntArrayList(primitives);
tList.reverse();
System.out.println(tList);
System.out.println(tList.size());
}
private static void guavaPrimitives(int[] primitives) { private static void guavaPrimitives(int[] primitives) {
ImmutableIntArray list = ImmutableIntArray.builder().addAll(primitives).build(); ImmutableIntArray immutableIntArray = ImmutableIntArray.builder().addAll(primitives).build();
System.out.println(immutableIntArray);
List<Integer> integers = Ints.asList(primitives); List<Integer> list = Ints.asList(primitives);
int[] primitive = Ints.toArray(Arrays.asList(1, 2, 3, 4, 5)); int[] primitiveArray = Ints.toArray(list);
System.out.println(Arrays.toString(primitive));
int[] concatenated = Ints.concat(primitiveArray, primitives);
System.out.println(Arrays.toString(concatenated));
} }
} }