ramkumar_s1
asked on
How do i count the number of elements in an array?
I am splitting the string using StringTokenizer. I also want to find the top and the bottom element of an array.
String mCust = request.getQueryString("cu st");
StringTokenizer st = new StringTokenizer(mCust, ",");
String[] tokens = new String[st.countTokens()];
int i = 0;
while(st.hasMoreElements() )
tokens[i++] = (String)st.nextElement();
---
Ramkumar
String mCust = request.getQueryString("cu
StringTokenizer st = new StringTokenizer(mCust, ",");
String[] tokens = new String[st.countTokens()];
int i = 0;
while(st.hasMoreElements()
tokens[i++] = (String)st.nextElement();
---
Ramkumar
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- Points to allahabad
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
girionis
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
- Points to allahabad
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
girionis
EE Cleanup Volunteer
that is a good way to get all and show the top and bottom.
but if you just want the top and bottom just store the first and last in two string vars rather than using an array
String mCust = Request.QueryString("cust"
StringTokenizer st = new StringTokenizer(mCust, ",");
int totTokens = st.countTokens();
String firstToken = null;
String lastToken = null;
int i = 0;
while(st.hasMoreElements()
if (i == 0) {
firstToken = st.nextToken();
}
else if (i == (totTokens-1)) {
lastToken = st.nextToken();
}
else {
String dummyString = st.nextToken();
dummyString = null;
}
i++;
}
System.out.println("Top token : " + firstToken);
System.out.println("Bottom
CJ