Results 1 to 3 of 3
Thread: Print String from an Array
- 02-18-2010, 03:36 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 4
- Rep Power
- 0
Print String from an Array
Hello All,
I have an array with given string that has two fields. I want to check the data in the field one and print data in filed two. So my array has following elements:-
{
CINSTALLDIR CM
CINSTALLDIR CT
CINSTALLDIR PJ
CINSTALLDIR RM
CINSTALLDIR RX
CINSTALLDIR SV
CINSTALLDIR TM
INSTALLDIR CT
INSTALLDIR PJ
INSTALLDIR TM
MINSTALLDIR CM
MINSTALLDIR RX
MINSTALLDIR SV
}
And the output i desire is:-
CINSTALLDIR CM CT PJ RM RX SV TM
INSTALLDIR CT PJ TM
MINSTALLDIR CM RX SV
So what i did till now is this, I am not able to apply the proper logic. Could you please guide me what i am doing wrong? or some other approach.
Thanks
Aditya
Java Code:public class StringSplit { public static void main(String[] args){ String[] test = {"CINSTALLDIR CM", "CINSTALLDIR CT", "CINSTALLDIR PJ", "CINSTALLDIR RM", "CINSTALLDIR RX", "CINSTALLDIR SV", "CINSTALLDIR TM ", "INSTALLDIR CT", "INSTALLDIR PJ", "INSTALLDIR TM", "MINSTALLDIR CM", "MINSTALLDIR RX", "MINSTALLDIR SV"}; for(int i=0;i<test.length;i++){ String j = test[i]; String[] Regex = j.split(" "); if(Regex[0].contains(Regex[0])){ System.out.print(Regex[1]); } } } }
- 02-18-2010, 04:04 PM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 12
Umm, what exactely were you trying to do with:
Java Code:if(Regex[0].contains(Regex[0]))
- 02-18-2010, 04:10 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
I can only print string literals
By leeavital in forum New To JavaReplies: 1Last Post: 12-11-2009, 01:20 AM -
How to print chars with symbols from a string
By blacksky in forum New To JavaReplies: 23Last Post: 01-06-2009, 01:14 PM -
How to print an object-filled array?
By Verna_Venisa in forum New To JavaReplies: 1Last Post: 10-20-2008, 08:09 PM -
How to save name in Array and Print saved Name
By ppkkyaw in forum New To JavaReplies: 4Last Post: 06-15-2008, 06:44 AM -
I can't seem to pass the value of a string variable into a string array
By mathias in forum Java AppletsReplies: 1Last Post: 08-03-2007, 10:52 AM
Bookmarks