Showing posts with label Array. Show all posts
Showing posts with label Array. Show all posts

Tuesday, 17 May 2011

To find minimum and maximum value.

private static int getMaxValue(int[] Value){
double maxValue = Value[0];
for(int i=1;i < Value.length;i++){
if(Value[i] > maxValue){
maxValue = Value[i];
}
}
return maxValue;
}
private static int getMinValue(int[] Value){
double maxValue = Value[0];
for(int i=1;i < Value.length;i++){
if(Value[i] < maxValue){
maxValue = Value[i];
}
}
return maxValue;
}

You can simply copy and paste these methods in your program. You can send array of values as parameter and get minimum or maximum value.

You can also change method return type and type of array to get minimum or maximum of double values

Concat array in JAVA || GWT

By this way array two array can be combine to make one.
This can be used to make size of array variable (virtually).
Objects can be added to the array whose size is defined and array is full.

String[] Value=new String[1];
String[] Value_prev;
String[] Value_temp = new String[10];
Value_prev = Value;

Value = new String[Value_temp.length+Value_prev.length];
System.arraycopy(Value_prev, 0, Value, 0, Value_prev.length-1);
System.arraycopy(Value_temp, 0, Value, Value_prev.length, Value_temp.length-1);

In this code Value is main array where Value_temp array's data is added and Value_prev array is for storing previous data. This can be looped and used to add any many items as desired breaking the limitation of array to be defined at beginning.

This is presently for single dimension which can be extended to multi dimension.