Results 1 to 5 of 5
  1. #1
    Mogmash is offline Member
    Join Date
    Nov 2012
    Location
    South Africa, Johannesburg
    Posts
    3
    Rep Power
    0

    Post Java Arrays( Searching ) Please help.

    Hi

    I want to seach the array ( index by index ) the return matches.
    The code below only gets a macth on index[0] then ignores the rest

    Please help

    kind regards

    Mogmash



    Java Code:
    
    final static    String[] array_A  =  {"AJS"};
    public final String   Str = "AISRA";
    final static    String[] inStr= new String[20];
    
    
    ///get & set
    public static void getEnter()
      {
        for(int i=0;i<Str.length();i++)
    	{
    		num_of_char = i;
    	  inWord [i] = String.valueOf(Str.charAt(i));
    
    	}
    	
    sr();
      }
    
    // below is where i think there is something wrong with the code
    
    
    
    
    public static  void sr(){
    
    
    // Code 1
    
    for(int i=0;i<str.length();i++)
    	{
    	for (String s : array_A)
    if (s.startsWith (inStr[i]))
     printer(" 1 : "+s);
    	}
    	
    //Proceeding to next task
    
    
    
    // Code 2
    for(int i=0;i<Str.length();i++)
    	{
    
           if ( array_A[i].contains(inStr[i]))  
           {
    
          System.out. println(" 1 : ");
         
               	
           }    
    //Proceeding to next task
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: Java Arrays( Searching ) Please help.

    There seems to be a lot missing from the code you've posted, which is a bit confusing.
    For example 'inWord', 'num_of_char'...

    What is this code doing?
    Doesn't help that the indenting is uneven.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Mogmash is offline Member
    Join Date
    Nov 2012
    Location
    South Africa, Johannesburg
    Posts
    3
    Rep Power
    0

    Default Re: Java Arrays( Searching ) Please help.

    Java Code:
    import java.util.Properties;
    import javax.swing.*;
    import java.util.Collection;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    import java.util.*;
     @SuppressWarnings("unchecked")
    public class Mainc {
          
             
    final static    String[] array_A  =  {"AJS"};
    public static final String   Str = "ISRA";
    final static    String[] inStr= new String[20];
    
     public static void main(String[] args) {
           
            for(int i=0;i<Str.length();i++)
    	{
    			  inStr[i] = String.valueOf(Str.charAt(i));
    
    	}
    sr(); // Method  
           
        }
    
    // below is where i think there is something wrong with the code
    
    public static  void sr(){
    
    for(int i=0;i<Str.length();i++)
    	{
    
           if ( array_A[i].contains(inStr[i])) // It must mactch A and S  but it does not get them ????  
           {
    
          System.out. println(" 1 : ");
             
               
                  	
           } 
          	   
    //Proceeding to next task
    System.exit(0); //We exit for now
    }
       
    }
    
    }
    Last edited by Mogmash; 11-13-2012 at 06:37 PM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: Java Arrays( Searching ) Please help.

    Stick some debug (ie println statements) in there and see what the inStr variable holds after it has been created.
    Also add some into the loop in sr to see what it is comparing.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Java Arrays( Searching ) Please help.

    Moved from Advanced Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Searching in Lucene with Java
    By greekman123 in forum Lucene
    Replies: 2
    Last Post: 09-27-2012, 06:41 PM
  2. File to Array Writing and Searching Arrays
    By michaelJava in forum New To Java
    Replies: 0
    Last Post: 02-13-2012, 10:35 PM
  3. java searching from many files
    By manish250 in forum Advanced Java
    Replies: 0
    Last Post: 12-31-2010, 07:50 AM
  4. Searching arrays
    By drymsza1234 in forum New To Java
    Replies: 5
    Last Post: 12-03-2009, 05:23 PM
  5. Searching Arrays
    By BHCluster in forum New To Java
    Replies: 3
    Last Post: 07-26-2008, 05:55 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
  •