Dart combining elements in one number

Viewed 90

I have a list containing few elements like this: [1, 1, 2, 2, 3, 3]. I want to combine these numbers into one number without summing them so I want the final number to be: 112233; Is there a way to do it

2 Answers

You should use list.join() method:

List<int> list = [1, 1, 2, 2, 3, 3];
String concatList = list.join().toString();
print(concatList);

you can use reduce method from list

List<int> list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  String s = "";
  for(int i in list) {
    s += i.toString();
  }
int result = int.parse(s); //result = 12345678910

result maximum value is 2^63-1, otherwise you will get an overflow!!!

Related