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?



I have a string like _a01_a02_a03_ and another string like _2_1.5_4_ as input.I want to extract a0..

Answer / 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

More Core Java Interview Questions

What do you understand by access specifiers in Java?

0 Answers   Genpact,


Difference difference paint() and paintcomponent()?

0 Answers  


How is object created in java?

5 Answers   Cap Gemini,


Whats the difference between notify() and notifyall()?

0 Answers  


What is final access modifier in java?

0 Answers  






What is the difference between procedural and object-oriented programs?

0 Answers  


What is the advantage of preparedstatement over statement?

0 Answers  


How many types of array are there?

0 Answers  


How do you compare characters in java?

0 Answers  


Which Component subclass is used for drawing and painting?

1 Answers  


What are the different ways to handle exceptions?

0 Answers  


What does .equals do in java?

0 Answers  


Categories