Results 1 to 3 of 3
  1. #1
    adityasirohi is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default 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]);
    			 }
    		}
    	}
    }

  2. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    Umm, what exactely were you trying to do with:
    Java Code:
    if(Regex[0].contains(Regex[0]))

  3. #3
    adityasirohi is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default

    Hola,

    So the logic in my mind to to iterate over all the values in Regex[0] and print values in Regex[1] till the time values in Regex[0] are same. That is why i used
    Java Code:
    if(Regex[0].contains(Regex[0]))
    .
    Thanks
    Aditya

Similar Threads

  1. I can only print string literals
    By leeavital in forum New To Java
    Replies: 1
    Last Post: 12-11-2009, 02:20 AM
  2. How to print chars with symbols from a string
    By blacksky in forum New To Java
    Replies: 23
    Last Post: 01-06-2009, 02:14 PM
  3. How to print an object-filled array?
    By Verna_Venisa in forum New To Java
    Replies: 1
    Last Post: 10-20-2008, 09:09 PM
  4. How to save name in Array and Print saved Name
    By ppkkyaw in forum New To Java
    Replies: 4
    Last Post: 06-15-2008, 07:44 AM
  5. Replies: 1
    Last Post: 08-03-2007, 11:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •