-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIncreaseArraySize.java
52 lines (40 loc) · 1.27 KB
/
IncreaseArraySize.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Write a description of class testTextIO here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class IncreaseArraySize
{
// instance variables - replace the example below with your own
static String MYARRAY[] = new String[4];
static int COUNTER = 0;
public static void main (String[] args){
//addItem();
//listArray();
}
public static String addItem(String NEWITEM){
do{
if (NEWITEM.compareTo("end")!=0){
MYARRAY[COUNTER] = NEWITEM;
COUNTER++;
if (COUNTER == MYARRAY.length){
increaseArraySize();
}
}
}while(NEWITEM.compareTo("end")!=0);
return NEWITEM;
}
public static void listArray(){
for (int I=0;I<MYARRAY.length-1;I++){
System.out.println(I + " - " + MYARRAY[I]);
}
}
public static void increaseArraySize(){
System.out.print("Here we increase the size to ");
String TEMP[] = new String[MYARRAY.length*2];
System.arraycopy(MYARRAY, 0, TEMP, 0, MYARRAY.length);
MYARRAY = TEMP;
System.out.println(TEMP.length);
}
}