Tuesday, 17 May 2011

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.

No comments:

Post a Comment