Hi all,
Im trying to create program what is seraching all pharse combination from left to right, from txt file were at least 4 chars. Its working when i have in *.txt file only one word, but im trying to get it work with mutiple words in same time.
forexample: I have string quality: and all combinations are: uali, quali, ality, qualit, uality, lity, ualit, quality, qual, alit. If i have strings quality milk utput should be ---> uali, quali, ality, qualit, uality, lity, ualit, quality, qual, alit,milk etc
package test; import java.io.*; import java.util.*; final public class testSub { public static void main(String...args) throws FileNotFoundException { read(); } private static void read() throws FileNotFoundException { String string, sub; ArrayList<String>al=new ArrayList<String>(); int i = 0, c, length,count = 0; // Create Scanner object Scanner in = new Scanner(new File("words.txt")); // Read a string string = in.nextLine(); length = string.length(); for(c=0;c<length;c++) { for(i=1;i<=length-c;i++) { sub = string.substring(c,c+i); //System.out.println(sub); al.add(sub); } } HashSet hs = new HashSet(); hs.addAll(al); al.clear(); al.addAll(hs); for(String str:al) { if(str.length()>3){ System.out.println(str); } } } }