Fathi
check if a substring exists in a string
3 Answer(s)      4 years and 7 months ago
Posted in : Java Interview Questions

Please I jave an arraylist composed as follwoing [w1, w2, w3, w4, w1.w2.w3, w2.w3.w4, w3.w4, w2.w4, w1.w3, w1.w2]

w2.w4 is a subset of w2.w3.w4 ?how I recognize it

also

w1.w3 is a subset of w1.w2.w3 ?how I recognize it

same for w1.w2 in w1.w2.w3.

I nedd your help.

Thanks a lot

Advertisement
View Answers

June 11, 2012 at 8:17 PM


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class SubString {
public static void main(String args[]) throws IOException{
    ArrayList<String> list=new ArrayList<String>();
    try{
        FileReader fread=new FileReader("meta.txt");
        BufferedReader br=new BufferedReader(fread);
        String strLine;
        while((strLine=br.readLine())!=null){
            list.add(strLine);
        }
        System.out.println("enter the string");
    Scanner sc=new Scanner(System.in);
    String substring=sc.nextLine();
String sub=substring.substring(0,2);

    for(String s:list){
        if(s.substring(0, 2).equalsIgnoreCase(sub)){
            System.out.println(substring+" "+"is having subset and is subset of the following strings"+s.toString());
        }
    }
}
    catch(Exception e){
        System.out.println(e);
    }
}
}

i don't think i have achieved it completely but i have done some thing almost related to this topic



June 11, 2012 at 8:21 PM


import java.io.BufferedReader; 
import java.io.FileReader; 
import java.io.IOException; 
import java.util.ArrayList; 
import java.util.Scanner; 
public class SubString { 
public static void main(String args[]) throws IOException{ 
    ArrayList<String> list=new ArrayList<String>(); 
    try{ 
        FileReader fread=new FileReader("C:\\Documents and Settings\\venkatanaveen.jc\\Desktop\\meta.txt"); 
        BufferedReader br=new BufferedReader(fread); 
        String strLine; 
        while((strLine=br.readLine())!=null){ 
            list.add(strLine); 
        } 
        System.out.println("enter the string"); 
    Scanner sc=new Scanner(System.in); 
    String substring=sc.nextLine(); 
String sub=substring.substring(0,2); 

    for(String s:list){ 
if(s.substring(0, 2).equalsIgnoreCase(sub)){ 
System.out.println(substring+" "+"is having subset and is subset of the following strings"+s.toString()); 
        } 
    } 
} 
    catch(Exception e){ 
        System.out.println(e); 
    } 
} 
} 
i don't think i have achieved it completely but i have done some thing almost related to this topic


June 11, 2012 at 8:25 PM


i included all values into a .txt file and added to arraylist










Related Tutorials/Questions & Answers:
check if a substring exists in a string
check if a substring exists in a string  Please I jave an arraylist composed as follwoing [w1, w2, w3, w4, w1.w2.w3, w2.w3.w4, w3.w4, w2.w4, w1.w3, w1.w2] w2.w4 is a subset of w2.w3.w4 ?how I recognize it also w1.w3
How to check if a string contains a substring in iOS?
on the 'Check If Exists' button application will find the string and show...Function for checking the presence of a substring in a string (NSString... the presence of substring in a string (NSString) and there is no readymade function
Advertisements
string and substring
string and substring  bbbnnnmmm*ccc remove second asterick and display it as bbb*nnn mmm*ccc
string and substring
string and substring  my code is bbbnnnmmm*ccc how to remove the asterick at second position and display the code as bbb*nnn mmm*ccc
How to check whether database exists?
How to check whether database exists?  Hi, I have to create... to creating the database, i want to check whether database exists or not? How can i do this check. can any one help me on this. Please find thesample code
Check the File Exists in PHP Program
Check the File Exists in PHP Program  Hi, I trying to create a application to find or retrieve the existing files. So, Please help me or suggest any online reference that explain about the file exists function in PHP? Thanks
Search string using substring
Search string using substring  I want to print a string by searching a substring of that string. - i want to print email-ids from word files (resumes...*; class FileRead { public static void main(String[] args) { String
remove a substring from a string
remove a substring from a string  Please I jave an arraylist composed as follwoing [w1, w2, w3, w4, w1.w2.w3, w2.w3.w4, w3.w4, w2.w4, w1.w3, w1.w2] w2.w4 is a subset of w2.w3.w4 ?how I recognize it also w1.w3 is a subset
JSP check email exists or not
JSP check email exists or not In this tutorial, you will learn how to check from the database whether entered email-id exists or not. The given code accepts the email id from the user and check whether the given email id already
How to check a file exists or not in java.
Description: This example demonstrate how to check a file exits at a given path or not.  The method isFile() of the File class check for its existence...(String[] a) {     File findFile = 
String substring method example
.style1 { font-size: medium; } String substring() method example... a string. String class provide methods for finding substring from string. Method...:String = "Rose India"; var substring:String = str.substring(5,13
Check if parameter exists in servlet request
Check if parameter exists in servlet request... will see how to check is parameter exists in servlet request. In this example.... getParametersNames() : This method returns an Enumeration of String objects . We can use two
C String Substring
C String Substring       In this section, you will learn how to get the substring from a string in C. You can see in the given example, a string and a method substring
String substring(int beginIndex)
String substring(int beginIndex)   ... the substring(int beginIndex) method of String class. We are going to use substring(int beginIndex) method of String class in Java. The description of the code
Check Whether Record is already Exists or Not with Database Connectivity - Java Beginners
Check Whether Record is already Exists or Not with Database Connectivity  Hello Sir I want Program to Check Whether ID is Already exists in the database with Swing Application ,if It is Already Exists then I want To Show MsgBox
String substring(int beginIndex, int endIndex)
String substring(int beginIndex, int endIndex)  ... explanation about the substring(int beginIndex, int endIndex) method of String class. We are going to use substring(int beginIndex, int endIndex) method of String
Java Substring
of String is called substring. Substrings are also a String. Substring is used... this method to find out the substring from a given String. substring() method... which is a substring of the current String. This method is written in two forms
C Programming SubString Program
C Programming SubString Program  Sir I want to Check whether the Single Substring is present in the given 3 string. characters. eg if i entered... entered to check PROGRAM is exists in given three strings then output
PHP File Manipulation File existance checking Tutorial, PHP check file exists
File existence checking If you want to check whether a file exists, you should use file exists PHP function. Syntax: file_exists($path), where...=/images/file1.jpg; file_exists($DOCUMENT_ROOT.$TmpName); where $DOCUMENT_ROOT - PHP
write a java program for inserting a substring in to the given main string from a given position
write a java program for inserting a substring in to the given main string from a given position  write a java program for inserting a substring in to the given main string from a given position
C get Substring from String
C get Substring from String       This section illustrates you how to get the substring using... have consider will as str2 and the whole string as str1. The function strstr
SubString in Java
SubString(), a method of String class is used to get a part of original string.... If beginIndex is equal to length in SubString(int beginIndex) it will return empty String... String. Example of SubString in Java: import java.io.*; import
Substring in java
Substring in java   example:output 0f the code.. Input String:University of the Cordilleras Input Substring:of Output:1 ...use non static methods,don't use (.Substring).. ..please help me.. ..thank you.. deadline:November
Substring in java
Substring in java   example:output 0f the code.. Input String:University of the Cordilleras Input Substring:of Output:1 ...use non static methods,don't use (.Substring).. ..please help me.. ..thank you.. deadline:November
JPA Substring() Function
() function. The substring() function returns the some part of string arguments..., second is starting index and third is length of string . JPA Substring... JPA Substring() Function   
find and substring
String"); String findstring = keybord.readLine(); String substring = keybord.readLine(); findreplace(findstring,substring); } catch(IOException io...find and substring   **import java.io.BufferedReader; import
Check for any elements exists between the current position and the limit of a buffer.
Check for any elements exists between the current position and the limit of a buffer. In this tutorial you will see how to check for existence of any... method returns true when there exists atleast one element in the buffer
Check for number of elements exists between the current position and the limit of a buffer.
Check for number of elements exists between the current position and the limit of a buffer. In this tutorial you will see how to check for existence of any...;CharBufferDemo {   public static void main(String[] 
help with substring in c programing
. Please help with substring function,prompt the user for two strings and display whether or not the second string is a substring of the first string. Regards...help with substring in c programing  Hi I could not found programming
check
check  interface validateInfo { public void validate(String empcode, String password); } class updateInfo implements validateInfo { String empcode; String password; public void validate(String
Use of <fn:subString(String, int, int)> Tag of JSTL
Use of <fn:subString(String, int, int)> Tag of JSTL... and return string type. Syntax : java.lang.String substring...; <c:out value="${fn:substring(string,start,end)}"/>