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

Is string is a data type?

0 Answers  


What is a instance variable in java?

0 Answers  


What do you know about the garbage collector?

0 Answers  


when we write class.forName("any one class"); what happens actually?what it will return?explain stepwise?

6 Answers  


________ exception must be either caught or specified in throws class of the method.

1 Answers  


Given: 10. interface A { void x(); } 11. class B implements A { public void x() { } public voidy() { } } 12. class C extends B { public void x() {} } And: 20. java.util.List list = new java.util.ArrayList(); 21. list.add(new B()); 22. list.add(new C()); 23. for (A a:list) { 24. a.x(); 25. a.y();; 26. } What is the result? 1 Compilation fails because of an error in line 25. 2 The code runs with no output. 3 An exception is thrown at runtime. 4 Compilation fails because of an error in line 20.

3 Answers  


what is meant by Garbage collection?

0 Answers   Cap Gemini,


what is Thread?

6 Answers  


Is age discrete or continuous?

0 Answers  


What is ellipsis in java?

0 Answers  


relation between list and linked list

1 Answers   Infosys,


what r advatages of websphere? & how to deploy?

0 Answers   Saksoft,


Categories