ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  10 Reasons We Need Java 3.0
Subject:   Functional Methods (correction)
Date:   2002-12-16 19:45:51
From:   anonymous2
Response to: Functional Methods

Sorry, Java code in the examples does not look as expected. I'll try to use HTML tags.



"Traditional approach"


void addNumber(int[] arr,int n)
{
for(int i=0;i<arr.length;i++)
{
arr[i]+=n;
}
}


"Functional" approach:


functional int[] addNumber(int[] arr,int n)
{
int[] arret=new int[arr.length];
for(int i=0;i<arr.length;i++)
{
arret[i]=arr[i]+n;
}
return arret;
}
</pre>