I have a string like _a01_a02_a03_ and another string like
_2_1.5_4_ as input.I want to extract a01,a02... to a string
array and 2,1.5,etc to a double array with a01 corresponds
to 2 and a02 to 1.5 etc. Need code in core java.. Can you do
it?

Answer Posted / sam

final String str1 = "_a01_a02_a03";
final String str2 = "_2_1.5_4";
final String[][] strArray = new String[3]
[2];
final StringTokenizer objST1 = new
StringTokenizer(str1,"_");
final StringTokenizer objST2 = new
StringTokenizer(str2,"_");
int iCnt=0;
while (objST1.hasMoreTokens())
{
objST2.hasMoreTokens();
strArray[iCnt][0] = (String)
objST1.nextToken();
strArray[iCnt++][1] = (String)
objST2.nextToken();
}
for(iCnt=0;iCnt<3;)
System.out.println(strArray[iCnt][0]
+" "+strArray[iCnt++][1]);

Is This Answer Correct ?    17 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is mean by exception?

541


What is a map in java?

544


What is an anonymous class in java?

538


Can we clone singleton object in java?

558


What does this () mean in constructor chaining concept?

552






Does hashset allow duplicates in java?

576


What is the original name of java?

535


How do you generate random numbers in java?

508


What is an infinite loop? How infinite loop is declared?

566


how come we know the object is no more used in the class?

5400


Can we declare the static variables and methods in an abstract class?

542


What are the different types of data structures in java?

484


What is the size of string?

554


What are the types of strings?

555


What is boolean in java?

507