class GFG {
// Driver method
public static void main(String[] args)
{
int arr[] = { 5, 10, 15, 20, 25 };
// Using Ints.asList() method which wraps
// the primitive integer array as List of
// integer Type
List<Integer> myList = Ints.asList(arr);
// Displaying the elements
System.out.println(myList);
}
}
public static void main(String[] args) {
int foo[] = {1,2,3,4,5};
Iterable<Integer> fooBar = Ints.asList(foo);
for(Integer i : fooBar) {
System.out.println(i);
}
}
class ArrayUtils
{
public static void main(String[] args)
{
int arr[] = { 1, 2, 3, 4, 5 };
List<Integer> list = Ints.asList(arr);
System.out.println(list);
}
}
public void collectionArrayFeatures() {
/**
* This test case will present how to work with arrays or collections of primitives thanks to Google Guava. Only one code line is enough to
* create a List of ints, booleans.. - all Guava's wrappers provide the possibility to convert primitives of some type to List of this type with asList method.
*/
List<integer> years = Ints.asList(1980, 1985, 1987, 1989, 1991, 2001);
assertTrue("The 1st entry of the list should be 1980 but is "+years.get(0), years.get(0) == 1980);
assertTrue("The 2nd entry of the list should be 1980 but is "+years.get(1), years.get(1) == 1985);
assertTrue("The 3rd entry of the list should be 1980 but is "+years.get(2), years.get(2) == 1987);
assertTrue("The 4th entry of the list should be 1980 but is "+years.get(3), years.get(3) == 1989);
assertTrue("The 5th entry of the list should be 1980 but is "+years.get(4), years.get(4) == 1991);
assertTrue("The 6th entry of the list should be 1980 but is "+years.get(5), years.get(5) == 2001);
}
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5};
List<Integer> list = Ints.asList(arr);
Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), list);
}
static void deletecols(JTable table, int[] exp) {
Integer[] selcols;
try {
TableColumnModel tcm = table.getColumnModel();
selcols = ArrayUtils.toObject(table.getSelectedColumns());
Arrays.sort(selcols, Collections.reverseOrder());
List<Integer> explist = Ints.asList(exp);
for (int i : selcols) {
if (!explist.contains(i)) {
tcm.removeColumn(tcm.getColumn(i));
}
}
} catch (Exception e) {
Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, e);
}
}
public List<?> getValues(Tensor tensor){
DataType dataType = tensor.dataType();
switch(dataType){
case FLOAT:
return Floats.asList(TensorUtil.toFloatArray(tensor));
case DOUBLE:
return Doubles.asList(TensorUtil.toDoubleArray(tensor));
case INT32:
return Ints.asList(TensorUtil.toIntArray(tensor));
case INT64:
return Longs.asList(TensorUtil.toLongArray(tensor));
case STRING:
return Arrays.asList(TensorUtil.toStringArray(tensor));
case BOOL:
return Booleans.asList(TensorUtil.toBooleanArray(tensor));
default:
throw new IllegalArgumentException();
}
}
void setUp() {
this.striped = impl.get(numStripes);
stripes = new int[numStripes];
for (int i = 0; i < numStripes; i++) {
stripes[i] = i;
}
List<Integer> asList = Ints.asList(stripes);
Collections.shuffle(asList, new Random(0xdeadbeef));
// do bulk gets with exactly 10 keys (possibly <10 stripes) (or less if numStripes is smaller)
bulkGetSet = ImmutableList.copyOf(limit(cycle(asList), 10));
}
public void setAcceptableCodes(final int[] acceptableCodes) {
this.acceptableCodes = Ints.asList(acceptableCodes);
}
public void serialize(TypeToken<?> type, int[] obj, ConfigurationNode value) throws ObjectMappingException {
List<Integer> bytes = Ints.asList(obj);
value.setValue(ttlb, bytes);
}