Results 1 to 5 of 5
- 11-13-2012, 03:04 PM #1
Member
- Join Date
- Nov 2012
- Location
- South Africa, Johannesburg
- Posts
- 3
- Rep Power
- 0
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 }
- 11-13-2012, 03:22 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 11-13-2012, 06:25 PM #3
Member
- Join Date
- Nov 2012
- Location
- South Africa, Johannesburg
- Posts
- 3
- Rep Power
- 0
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.
- 11-14-2012, 09:28 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 11-14-2012, 05:02 PM #5
Similar Threads
-
Searching in Lucene with Java
By greekman123 in forum LuceneReplies: 2Last Post: 09-27-2012, 06:41 PM -
File to Array Writing and Searching Arrays
By michaelJava in forum New To JavaReplies: 0Last Post: 02-13-2012, 10:35 PM -
java searching from many files
By manish250 in forum Advanced JavaReplies: 0Last Post: 12-31-2010, 07:50 AM -
Searching arrays
By drymsza1234 in forum New To JavaReplies: 5Last Post: 12-03-2009, 05:23 PM -
Searching Arrays
By BHCluster in forum New To JavaReplies: 3Last Post: 07-26-2008, 05:55 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks