skip to Main Content

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


  1. 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!!!

    Login or Signup to reply.
  2. You should use list.join() method:

    List<int> list = [1, 1, 2, 2, 3, 3];
    String concatList = list.join().toString();
    print(concatList);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search