---
title: "Converting from <Datatype1>[] to <Datatype2>[]"  
description: "Converting from <Datatype1>[] to <Datatype2>[]"  
author: "Anonymous User"  
published: 2015-07-09  
updated: 2015-07-09  
canonical: https://www.mindstick.com/forum/23329/converting-from-datatype1-to-datatype2  
category: "java"  
tags: ["java", "collection", "array"]  
reading_time: 1 minute  

---

# Converting from <Datatype1>[] to <Datatype2>[]

Is it [possible to convert](https://answers.mindstick.com/qa/96585/is-it-possible-to-convert-a-presentation-into-a-video-if-yes-how) from a list of datatypes without going through the trouble of looping through the entire list.\
[I.e](https://answers.mindstick.com/qa/39877/what-state-was-the-first-to-enter-the-union-i-e-was-the-first-to-ratify-the-united-states-constitution):b = {"1", "2"}; [Integer](https://answers.mindstick.com/qa/113667/write-code-for-roman-to-integer)[] a = (Integer[]) b; //not actually [runnable](https://www.mindstick.com/forum/160962/what-is-the-difference-between-callable-and-runnable-in-java)\
Not really necessary, but it would be nice.

## Replies

### Reply by Anonymous User

In Java 8, you can do

```
Integer[] integerArray =     Stream.of(stringArray)          .map(Integer::parseInt)          .toArray(Integer[]::new);
```

If you want an int-Array, you can do:

```
int[] intArray = Stream.of(stringArray)      .mapToInt(Integer::parseInt)      .toArray();
```

Stream.of() creates a stream from the array. map maps every element of the stream to an Integer using Integer::parseInt. Using mapToInt, you can create an Intstream, which is a specialization of streams for integer primitives. Integer[]::new is a method reference to an array constructor.\
This assumes all elements of the array are parseable, if not it will throw an exception.


---

Original Source: https://www.mindstick.com/forum/23329/converting-from-datatype1-to-datatype2

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
