Once java-8 is out (March 2014) you’ll be able to use streams:
If you have a List<Integer>
int sum = list.stream().mapToInt(Integer::intValue).sum();
If it’s an int[]
int sum = IntStream.of(a).sum();
More Related Contents:
- What is the best way to implement constants in Java? [closed]
- What is the actual use of Class.forName(“oracle.jdbc.driver.OracleDriver”) while connecting to a database?
- Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2
- How to convert milliseconds to “hh:mm:ss” format?
- How to create an FXML file for an already created new component in java than add it to scene builder?
- Selenium many Logs (How to remove)
- Get the changed HTML content after it’s updated by Javascript? (htmlunit)
- Capture SIGINT in Java
- Java floating point high precision library [closed]
- Get filepath and filename of selected gallery image in Android
- How to iterate through range of Dates in Java?
- Java “Bit Shifting” Tutorial? [closed]
- How to create a new java.io.File in memory? [duplicate]
- @OneToMany and composite primary keys?
- Display omitted versions in maven dependency:tree?
- Using EhCache in Spring 4 without XML
- Hashmap concurrency issue
- Load arrayList data into JTable
- Displaying pdf in jsp
- Annotating the functional interface of a Lambda Expression
- Spring can’t autowire Map bean
- How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9
- How do I give Jenkins more heap space when it’s running as a daemon on Ubuntu?
- JpaRepository caches newly created object. How to refresh it?
- java timer task schedule
- How can I @Autowire a spring bean that was created from an external jar?
- Java and Clojure with Leiningen
- Fatal error by Java runtime environment
- Using accelerometer, gyroscope and compass to calculate device’s movement in 3D world
- Mocking behaviour resets after each test with PowerMock