2

I am a beginner in flutter how do i convert list of string into int. Below is the example code

var data="18:00";
List<String> dataList = data.split(':');
print(datalist[0]);
print(datalist[1]);

Output will be 18 and 00 under 18, so how do i get this 18 and 00 in int type.

1
  • 1
    int.parse(datalist[0]); Commented Dec 11, 2019 at 11:57

4 Answers 4

5

You can convert your list of String into a list of int by mapping through each element and parsing to an int.

  List<int> dataListAsInt = dataList.map((data) => int.parse(data)).toList();
Sign up to request clarification or add additional context in comments.

Comments

1

Just parse your data with int.parse(//your data)

var data="18:00";
List<String> dataList = data.split(':');
print(int.parse(dataList[0]));
print(int.parse(dataList[1]));

Comments

1

you can do this like:

var data="18:00";
List<String> dataList = data.split(':');    
for(String s in datalist){
  int a=int.parse(s);
  print(a);
}

hope this will help you

Comments

0

How to convert string to int

int.parse(data.split(':')) // this is how

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.