---
title: "Calculations with array list elements."  
description: "Calculations with array list elements."  
author: "Lillian Martin"  
published: 2014-10-29  
updated: 2014-10-29  
canonical: https://www.mindstick.com/forum/2452/calculations-with-array-list-elements  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Calculations with array list elements.

I have an [integer](https://answers.mindstick.com/qa/113667/write-code-for-roman-to-integer) [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) list. It will always contain 5 integers. [Now](https://yourviews.mindstick.com/view/81402/it-s-liberals-vs-progressives-in-us-politics-now) suppose it contains the numbers 10031. Now I want to do this [calculation](https://www.mindstick.com/forum/160723/factorial-calculation) in the elements.\
[Add](https://www.mindstick.com/forum/12983/add-address-in-textbox-when-page-is-load-and-if-i-search-address-in-textbox-show-in-map-by-javascript) the numbers within this number, until you are [left](https://www.mindstick.com/articles/12768/don-t-be-left-behind-with-the-new-it-revolution) with a 1 or 2 digit number.\
1.....0.....0.....3.....1\
...1.....0......3....4\
.......1.....3.....7\
...........4....10 (When this occurs, separate into 1 + 0)\
..............5..1 = 51. [Result](https://www.mindstick.com/blog/12011/advantages-of-getting-result-oriented-seo-from-an-agency) is 51.\
I want the result when it is a double digit number. Please help.

## Replies

### Reply by Anonymous User

try this:

```
public static int yourFunction(ArrayList<Integer> list){    String numbers = "";      for(Integer i : list){        numbers += String.valueOf(i);    }     String tmp_numbers;     while(numbers.length() > 2){        tmp_numbers = "";        for(int i = 0; i < numbers.length()-1; ++i){             int v = Integer.parseInt(numbers.substring(i,i+1));                 v +=
Integer.parseInt(numbers.substring(i+1,i+2));             tmp_numbers = tmp_numbers + String.valueOf(v);         }        numbers = tmp_numbers;     }    return Integer.parseInt(numbers);}
```


---

Original Source: https://www.mindstick.com/forum/2452/calculations-with-array-list-elements

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
