hi,
i am having a prob with my array list arrCount. see the code below
import java.util.ArrayList;
import java.util.StringTokenizer;
public class SplitData {
static ArrayList arrData = new ArrayList();
static ArrayList<Integer> arrCount = new ArrayList<Integer>();
static int size = 0;
static int i = 0;
static String data;
public static void main(String args[]){
ArrayList arr = new ArrayList();
arr.add("hotelw-roomtypew-200.12-descriptionw");
arr.add("hotelx-roomtypex-220.16-roomtypex2-230.52-descriptionx");
arr.add("hotely-roomtypey-219.23-roomtypey2-245.02-roomtypey3-250.32-descriptionx");
arr.add("hotelz-roomtypez-217.30-descriptionz");
String delimeter="-";
SplitData sd = new SplitData();
sd.getDetails(arr, delimeter);
int s = 0;
int arrSize = sd.arrData.size();
int c = 0;
int countDisp = 0;
//System.out.println("\n arrData: " + size );
while((s < arrSize)){
System.out.println("\n No: " + s );
while(c < sd.arrCount.get(s)){
System.out.println("\n Data: " + c +"= " + sd.arrData.get(c));
c++;
}
s++;
}
}
public static void getDetails(ArrayList arr, String delimeter){
size = arr.size();
int m=0;
int count = 0;
while(i < size){
data = (String) arr.get(i);
System.out.println("data: " + data);
StringTokenizer st1 = new StringTokenizer(data, delimeter);
while(st1.hasMoreTokens()){
arrData.add(st1.nextToken(delimeter));
count++;
}
arrCount.add(count);
i++;
}
}
}
my first array arr contains data about hotels, like name, roontype, price n description.
this i'll b getting it from another code but for ne am placing z main in SplitData itself to test it
the data in arr will be for example "hotelw-roomtypew-200.12-descriptionw"
i split them using stringtokenizer zis part is ok.
since all hotels wont hve same no of roomtypes available, i made use of count so as to know in each posn of arr hw many data were split.
then i place in in arrCount whereas for z data i place it in arrData.
now the data in arr i need it to insert in databse
but i was testing b4 i do z insertion if i do get the values like i wanted.
n you will see in z main that i did 2 while loops
the BIG PROB comes here
i did while((s < arrSize)) n when s is incremented n becomes finally equal to arrSize it shouldnt hve entered the while loop
but unfortunately here it does enter the loop dont know why or where i did a mistake
n causes a mistake when i do sd.arrCount.get(s) cauz the the max data in arrcount is 4 n for array it starts from 0
n since in the sd.arrCount.get(4) we are nw accessing its 4th posn n theres no data there we get this err
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at SplitData.main(SplitData.java:42)
i thought wat i did would work since according to z condition i place for the 1st while loop in z main it shouldnt hve entered the loop in z first place
unless am definitely wrong smewhere
can any1 one plz try help me out plz????
its very urgent
thking u in advance for ur help
may god bless u all
Regards
Mushy
i am having a prob with my array list arrCount. see the code below
import java.util.ArrayList;
import java.util.StringTokenizer;
public class SplitData {
static ArrayList arrData = new ArrayList();
static ArrayList<Integer> arrCount = new ArrayList<Integer>();
static int size = 0;
static int i = 0;
static String data;
public static void main(String args[]){
ArrayList arr = new ArrayList();
arr.add("hotelw-roomtypew-200.12-descriptionw");
arr.add("hotelx-roomtypex-220.16-roomtypex2-230.52-descriptionx");
arr.add("hotely-roomtypey-219.23-roomtypey2-245.02-roomtypey3-250.32-descriptionx");
arr.add("hotelz-roomtypez-217.30-descriptionz");
String delimeter="-";
SplitData sd = new SplitData();
sd.getDetails(arr, delimeter);
int s = 0;
int arrSize = sd.arrData.size();
int c = 0;
int countDisp = 0;
//System.out.println("\n arrData: " + size );
while((s < arrSize)){
System.out.println("\n No: " + s );
while(c < sd.arrCount.get(s)){
System.out.println("\n Data: " + c +"= " + sd.arrData.get(c));
c++;
}
s++;
}
}
public static void getDetails(ArrayList arr, String delimeter){
size = arr.size();
int m=0;
int count = 0;
while(i < size){
data = (String) arr.get(i);
System.out.println("data: " + data);
StringTokenizer st1 = new StringTokenizer(data, delimeter);
while(st1.hasMoreTokens()){
arrData.add(st1.nextToken(delimeter));
count++;
}
arrCount.add(count);
i++;
}
}
}
my first array arr contains data about hotels, like name, roontype, price n description.
this i'll b getting it from another code but for ne am placing z main in SplitData itself to test it
the data in arr will be for example "hotelw-roomtypew-200.12-descriptionw"
i split them using stringtokenizer zis part is ok.
since all hotels wont hve same no of roomtypes available, i made use of count so as to know in each posn of arr hw many data were split.
then i place in in arrCount whereas for z data i place it in arrData.
now the data in arr i need it to insert in databse
but i was testing b4 i do z insertion if i do get the values like i wanted.
n you will see in z main that i did 2 while loops
the BIG PROB comes here
i did while((s < arrSize)) n when s is incremented n becomes finally equal to arrSize it shouldnt hve entered the while loop
but unfortunately here it does enter the loop dont know why or where i did a mistake
n causes a mistake when i do sd.arrCount.get(s) cauz the the max data in arrcount is 4 n for array it starts from 0
n since in the sd.arrCount.get(4) we are nw accessing its 4th posn n theres no data there we get this err
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at SplitData.main(SplitData.java:42)
i thought wat i did would work since according to z condition i place for the 1st while loop in z main it shouldnt hve entered the loop in z first place
unless am definitely wrong smewhere
can any1 one plz try help me out plz????
its very urgent
thking u in advance for ur help
may god bless u all
Regards
Mushy