Convert (ArrayLists) in java android












0















If I have Arraylist<Integer> how can I do convert it to ArrayList<String>



final ArrayList<Integer> arrayList = 
new ArrayList<Integer>(asList(19,85,955,9,2,62,96,2,6,26,2,26,2));


the Toast did not print any think on the Screen



ListView listView=findViewById(R.id.arraylistv);
final ArrayList<Integer> arrayList=new ArrayList<Integer>(asList(19,85,955,9,2,62,96,2,6,26,2,26,2));
final ArrayAdapter< Integer> arrayAdapter =new ArrayAdapter<Integer>(this , android.R.layout.simple_list_item_activated_1,arrayList);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

Toast.makeText(getApplicationContext(),"your num is "+arrayList,Toast.LENGTH_LONG);
}
});









share|improve this question




















  • 1





    It's already an ArrayList?

    – flakes
    Nov 23 '18 at 21:39













  • What do you mean? As flakes said it is already an ArrayList? How do you convert an int to an int?

    – Ishaan Javali
    Nov 23 '18 at 21:41











  • Do you mean how to populate a List with values using asList? Then you miss the static import java.util.Arrays.

    – Glains
    Nov 23 '18 at 21:43











  • target array contains String and not Integer? you maybe could try something like that : 'listInt.stream.map(String::valueOf).collect(Collectors.toList())'

    – boly38
    Nov 23 '18 at 22:18











  • what have you tried so far ? where is your code ? switching from Integer to String is very well documented all over the internet, did you search into the java doc or java online courses ?

    – LoneWanderer
    Nov 23 '18 at 22:39
















0















If I have Arraylist<Integer> how can I do convert it to ArrayList<String>



final ArrayList<Integer> arrayList = 
new ArrayList<Integer>(asList(19,85,955,9,2,62,96,2,6,26,2,26,2));


the Toast did not print any think on the Screen



ListView listView=findViewById(R.id.arraylistv);
final ArrayList<Integer> arrayList=new ArrayList<Integer>(asList(19,85,955,9,2,62,96,2,6,26,2,26,2));
final ArrayAdapter< Integer> arrayAdapter =new ArrayAdapter<Integer>(this , android.R.layout.simple_list_item_activated_1,arrayList);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

Toast.makeText(getApplicationContext(),"your num is "+arrayList,Toast.LENGTH_LONG);
}
});









share|improve this question




















  • 1





    It's already an ArrayList?

    – flakes
    Nov 23 '18 at 21:39













  • What do you mean? As flakes said it is already an ArrayList? How do you convert an int to an int?

    – Ishaan Javali
    Nov 23 '18 at 21:41











  • Do you mean how to populate a List with values using asList? Then you miss the static import java.util.Arrays.

    – Glains
    Nov 23 '18 at 21:43











  • target array contains String and not Integer? you maybe could try something like that : 'listInt.stream.map(String::valueOf).collect(Collectors.toList())'

    – boly38
    Nov 23 '18 at 22:18











  • what have you tried so far ? where is your code ? switching from Integer to String is very well documented all over the internet, did you search into the java doc or java online courses ?

    – LoneWanderer
    Nov 23 '18 at 22:39














0












0








0








If I have Arraylist<Integer> how can I do convert it to ArrayList<String>



final ArrayList<Integer> arrayList = 
new ArrayList<Integer>(asList(19,85,955,9,2,62,96,2,6,26,2,26,2));


the Toast did not print any think on the Screen



ListView listView=findViewById(R.id.arraylistv);
final ArrayList<Integer> arrayList=new ArrayList<Integer>(asList(19,85,955,9,2,62,96,2,6,26,2,26,2));
final ArrayAdapter< Integer> arrayAdapter =new ArrayAdapter<Integer>(this , android.R.layout.simple_list_item_activated_1,arrayList);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

Toast.makeText(getApplicationContext(),"your num is "+arrayList,Toast.LENGTH_LONG);
}
});









share|improve this question
















If I have Arraylist<Integer> how can I do convert it to ArrayList<String>



final ArrayList<Integer> arrayList = 
new ArrayList<Integer>(asList(19,85,955,9,2,62,96,2,6,26,2,26,2));


the Toast did not print any think on the Screen



ListView listView=findViewById(R.id.arraylistv);
final ArrayList<Integer> arrayList=new ArrayList<Integer>(asList(19,85,955,9,2,62,96,2,6,26,2,26,2));
final ArrayAdapter< Integer> arrayAdapter =new ArrayAdapter<Integer>(this , android.R.layout.simple_list_item_activated_1,arrayList);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

Toast.makeText(getApplicationContext(),"your num is "+arrayList,Toast.LENGTH_LONG);
}
});






java android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 23:08







Eslam Magdy

















asked Nov 23 '18 at 21:33









Eslam MagdyEslam Magdy

63




63








  • 1





    It's already an ArrayList?

    – flakes
    Nov 23 '18 at 21:39













  • What do you mean? As flakes said it is already an ArrayList? How do you convert an int to an int?

    – Ishaan Javali
    Nov 23 '18 at 21:41











  • Do you mean how to populate a List with values using asList? Then you miss the static import java.util.Arrays.

    – Glains
    Nov 23 '18 at 21:43











  • target array contains String and not Integer? you maybe could try something like that : 'listInt.stream.map(String::valueOf).collect(Collectors.toList())'

    – boly38
    Nov 23 '18 at 22:18











  • what have you tried so far ? where is your code ? switching from Integer to String is very well documented all over the internet, did you search into the java doc or java online courses ?

    – LoneWanderer
    Nov 23 '18 at 22:39














  • 1





    It's already an ArrayList?

    – flakes
    Nov 23 '18 at 21:39













  • What do you mean? As flakes said it is already an ArrayList? How do you convert an int to an int?

    – Ishaan Javali
    Nov 23 '18 at 21:41











  • Do you mean how to populate a List with values using asList? Then you miss the static import java.util.Arrays.

    – Glains
    Nov 23 '18 at 21:43











  • target array contains String and not Integer? you maybe could try something like that : 'listInt.stream.map(String::valueOf).collect(Collectors.toList())'

    – boly38
    Nov 23 '18 at 22:18











  • what have you tried so far ? where is your code ? switching from Integer to String is very well documented all over the internet, did you search into the java doc or java online courses ?

    – LoneWanderer
    Nov 23 '18 at 22:39








1




1





It's already an ArrayList?

– flakes
Nov 23 '18 at 21:39







It's already an ArrayList?

– flakes
Nov 23 '18 at 21:39















What do you mean? As flakes said it is already an ArrayList? How do you convert an int to an int?

– Ishaan Javali
Nov 23 '18 at 21:41





What do you mean? As flakes said it is already an ArrayList? How do you convert an int to an int?

– Ishaan Javali
Nov 23 '18 at 21:41













Do you mean how to populate a List with values using asList? Then you miss the static import java.util.Arrays.

– Glains
Nov 23 '18 at 21:43





Do you mean how to populate a List with values using asList? Then you miss the static import java.util.Arrays.

– Glains
Nov 23 '18 at 21:43













target array contains String and not Integer? you maybe could try something like that : 'listInt.stream.map(String::valueOf).collect(Collectors.toList())'

– boly38
Nov 23 '18 at 22:18





target array contains String and not Integer? you maybe could try something like that : 'listInt.stream.map(String::valueOf).collect(Collectors.toList())'

– boly38
Nov 23 '18 at 22:18













what have you tried so far ? where is your code ? switching from Integer to String is very well documented all over the internet, did you search into the java doc or java online courses ?

– LoneWanderer
Nov 23 '18 at 22:39





what have you tried so far ? where is your code ? switching from Integer to String is very well documented all over the internet, did you search into the java doc or java online courses ?

– LoneWanderer
Nov 23 '18 at 22:39












1 Answer
1






active

oldest

votes


















4














You can use streams to easily convert type of a List, like this:



List<Integer> input = Arrays.asList(19,85,955,9,2,62,96,2,6,26,2,26,2);
List<String> result = input.stream().map(String::valueOf).collect(Collectors.toList());


In this case, we're using map to convert each element using String::valueOf - which basically is a function that converts the input into a string. You can replace this with any other function to convert the input type to other types.






share|improve this answer



















  • 1





    If you really need to to be an ArrayList you can also do input.stream().map(String::valueOf).collect(Collectors.toCollection(ArrayList::new))

    – flakes
    Nov 23 '18 at 22:46











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453168%2fconvert-arraylists-in-java-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














You can use streams to easily convert type of a List, like this:



List<Integer> input = Arrays.asList(19,85,955,9,2,62,96,2,6,26,2,26,2);
List<String> result = input.stream().map(String::valueOf).collect(Collectors.toList());


In this case, we're using map to convert each element using String::valueOf - which basically is a function that converts the input into a string. You can replace this with any other function to convert the input type to other types.






share|improve this answer



















  • 1





    If you really need to to be an ArrayList you can also do input.stream().map(String::valueOf).collect(Collectors.toCollection(ArrayList::new))

    – flakes
    Nov 23 '18 at 22:46
















4














You can use streams to easily convert type of a List, like this:



List<Integer> input = Arrays.asList(19,85,955,9,2,62,96,2,6,26,2,26,2);
List<String> result = input.stream().map(String::valueOf).collect(Collectors.toList());


In this case, we're using map to convert each element using String::valueOf - which basically is a function that converts the input into a string. You can replace this with any other function to convert the input type to other types.






share|improve this answer



















  • 1





    If you really need to to be an ArrayList you can also do input.stream().map(String::valueOf).collect(Collectors.toCollection(ArrayList::new))

    – flakes
    Nov 23 '18 at 22:46














4












4








4







You can use streams to easily convert type of a List, like this:



List<Integer> input = Arrays.asList(19,85,955,9,2,62,96,2,6,26,2,26,2);
List<String> result = input.stream().map(String::valueOf).collect(Collectors.toList());


In this case, we're using map to convert each element using String::valueOf - which basically is a function that converts the input into a string. You can replace this with any other function to convert the input type to other types.






share|improve this answer













You can use streams to easily convert type of a List, like this:



List<Integer> input = Arrays.asList(19,85,955,9,2,62,96,2,6,26,2,26,2);
List<String> result = input.stream().map(String::valueOf).collect(Collectors.toList());


In this case, we're using map to convert each element using String::valueOf - which basically is a function that converts the input into a string. You can replace this with any other function to convert the input type to other types.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 22:20









KreaseKrease

11.6k74160




11.6k74160








  • 1





    If you really need to to be an ArrayList you can also do input.stream().map(String::valueOf).collect(Collectors.toCollection(ArrayList::new))

    – flakes
    Nov 23 '18 at 22:46














  • 1





    If you really need to to be an ArrayList you can also do input.stream().map(String::valueOf).collect(Collectors.toCollection(ArrayList::new))

    – flakes
    Nov 23 '18 at 22:46








1




1





If you really need to to be an ArrayList you can also do input.stream().map(String::valueOf).collect(Collectors.toCollection(ArrayList::new))

– flakes
Nov 23 '18 at 22:46





If you really need to to be an ArrayList you can also do input.stream().map(String::valueOf).collect(Collectors.toCollection(ArrayList::new))

– flakes
Nov 23 '18 at 22:46




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453168%2fconvert-arraylists-in-java-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen