Java: find elements of one array in another array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alex1984
    New Member
    • Oct 2015
    • 8

    Java: find elements of one array in another array

    I'm trying to write a program that reads words from one array and then finds their definitions in another array.
    Here is what I have:
    Code:
    import java.io.IOException;
    
    public class Sampler{	
    public static void main(String[] args) throws IOException{
    	String[] wordArray ={"Intelligible","Cripple","Bleeper","Accumulate","Envelope","Horse","Gland","Oatmeal","Quarantine","Strait"};
    
    ReadDictionaryLines rf = new ReadDictionaryLines(); // class that reads dictionary.txt file          
    String filename = "dictionary.txt";           
    String[] lines = rf.readLines(filename); // Array holds dictionary lines  	                
    	   }         	                		
    }
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    It looks all ok.
    But if you want to find something, then an array is definitely the wrong data structure. Just use ArrayList instead. Then you do not need to loop through the array with a for-loop, but can use the contains() und indexOf() methods.

    Please show us your implementation of class ReadDictionaryL ines that you have done so far.
    So where's your problem there , where are you stuck?

    Comment

    Working...