without using built-in functions

without using built-in functions

Hai sir...

Please help me to solve this...

Findout occurances of each string in every another string (built - in functions are not at all allowed)

all, and, sand, falling wall and sand

View Answers

October 8, 2012 at 5:01 PM

Here is a java example that finds the occurrences of each string in every another string.

class  Occurrence
{
    public static void main(String[] args) 
    {
    String str = "all and sand falling wall and sand";
    String findStr = "and";
    int lastIndex = 0;
    int count = 0;

    while ((lastIndex = str.indexOf(findStr, lastIndex)) != -1) {
        count++;
        lastIndex += findStr.length() - 1;
    }

    System.out.println(findStr+" occurs " +count+ " times");

    }
}

October 8, 2012 at 5:02 PM

Here is another code.

import java.util.*;

public class CountWordOccurrence {
        public static void main(String[] args){

        String[] st = {"all","and","sand","falling wall","and","sand"};
        HashMap<String, Integer> map = new HashMap<String, Integer>();
            String str="";
            for(int i=0;i<st.length;i++){
                str+=st[i]+" ";
            }
            str = str.toLowerCase(); 
                int count = -1;
                for (int i = 0; i < str.length(); i++) { 
                   if ((!Character.isLetter(str.charAt(i))) || (i + 1 == str.length())) { 
                            if (i - count > 1) { 
                            if (Character.isLetter(str.charAt(i))) 
                                i++;
                            String word = str.substring(count + 1, i);
                            if (map.containsKey(word)) { 
                            map.put(word, map.get(word) + 1);
                            }
                            else { 
                            map.put(word, 1);
                            } 
                        } 
                        count = i;
                    } 
                } 
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.addAll(map.values());
        Collections.sort(list, Collections.reverseOrder());
        int last = -1;
        for (Integer i : list) { 
            if (last == i) 
                continue;
            last = i;
            for (String s : map.keySet()) { 
                if (map.get(s) == i) 
                    System.out.println(s + ":" + i);
            } 
        } 
    } 
}









Related Tutorials/Questions & Answers:
without using built-in functions
without using built-in functions  Hai sir... Please help me to solve this... Findout occurances of each string in every another string (built - in functions are not at all allowed) all, and, sand, falling wall and sand
Program to Find Cube Root of any Number without using built in function
Program to Find Cube Root of any Number without using built in function  Please help me in finding cube root of any number without using Built in function in java
Advertisements
Java reverse string without using inbuilt functions
Java reverse string without using inbuilt functions In this tutorial, you will learn how to reverse string without using any inbuilt functions. Here, we have created a method to reverse the string and returns a new string with reverse
using tiles without struts
using tiles without struts  Hi I am trying to make an application using tiles 2.0. Description of my web.xml is as follows: tiles org.apache.tiles.web.startup.TilesServlet
Add year to Date without using Calendar in java
Add year to Date without using Calendar in java  how could i add a year to a date function without using calendar functions
messages to the screen without using "document.write()"
messages to the screen without using "document.write()"  To write messages to the screen without using "document.write
Without Using Form in Java Script
Without Using Form in Java Script  HOw to Reset the data in javascript without using form tag
Pagination without using database in php
Pagination without using database in php  How can I show multiple images in multiple rows with pagination in php
Sorting arraylist without using Collection.sort()
Sorting arraylist without using Collection.sort()  Hi, How can I sort an arraylist without using Collection.sort() nad also I am not allowed to use any other data structure in the program? Is there any algorithm by using which I
Built in Data Format in Excel Using POI 3.0
Built in Data Format in Excel Using POI 3.0       In this program we are using the built... OLE 2 Compound Document format using Java .POI version 3.0 APIs provides
Draw graph using jsp without database connection
Draw graph using jsp without database connection  Draw graph using jsp code without database connection
Round of to a multiple of 5 without using function
Round of to a multiple of 5 without using function  Please help me out... U enter values like 239, 2543.876, 962.... Give me an equation without using any function which will give output of 240, 2545, 960 respectively
Round of to a multiple of 5 without using function
Round of to a multiple of 5 without using function  Please help me out... U enter values like 239, 2543.876, 962.... Give me an equation without using any function which will give output of 240, 2545, 960 respectively
Breaking a string into words without using StringTokenizer
Breaking a string into words without using StringTokenizer  how can we Break a string into words without using StringTokenizer ??   The given code convert the string into words. import java.util.*; class StringExample
String length without using length() method in java
String length without using length() method in java  How to count length of string without using length() method in java?   Here is Example... the number of character into the given string without using the length() method
send without authentication mail using java - JavaMail
send without authentication mail using java  Dear All, I am tring to send simple mail without authentication using java. is it possible, could i send email without authentication. I have written following code. public
Java repeat string without using loops
Java repeat string without using loops In this section, you will learn how to repeat string without using for loops. The given example accepts the number of times and iterates the string to the number of times set by the user without
retrive image from database using jsp without stream
retrive image from database using jsp without stream  How to retrive image from database using jsp without stream like (inputStream
how to delete a row in sql without using delete command.
how to delete a row in sql without using delete command.  how to delete a row in sql without using delete command. thanks in advance
how to validate the telephone number without using jquery in html with javascript
how to validate the telephone number without using jquery in html with javascript  how to validate the telephone number without using jquery in html with javascript
without ;
without ;  can u give me an example of a program without
without ;
without ;  can u give me an example of a program without
Swap two numbers without using third variable
Swap two numbers without using third variable In this section we are going to swap two variables without using the third variable. For this, we have used... from the command prompt. Instead of using temporary variable, we have done some
Math Constants and Functions using JavaScript
Math Constants and Functions using JavaScript  What's Math Constants and Functions using JavaScript
associate functions with objects using JavaScript
associate functions with objects using JavaScript  How to associate functions with objects using JavaScript
Retriving data from MYSQL without line break using java
Retriving data from MYSQL without line break using java  get data without line breaking from mysql table (i.e data stored as mediumtext )using java
Connect a linux machine from linux using java program without password
Connect a linux machine from linux using java program without password  Connect a linux machine from linux using java program without password. Can anyone help me
how can i achieve multiple inheritance in java without using inheritance ?
how can i achieve multiple inheritance in java without using inheritance ?  how can i achieve multiple inheritance in java without using inheritance
getting current date without using system date - Date Calendar
getting current date without using system date  I want to get the current date but the Java code should not get System date as Current date. Pleae help me in getting current date without using system date. thanks in Advance
how to build a colorful clock in JSP without using Flash.
how to build a colorful clock in JSP without using Flash.  I have to make a colorful clock using java programming or some API in a JSP page. Please send me a code for it as soon as possible
dyanamic upload of images using struts without database connection
dyanamic upload of images using struts without database connection  I want to upload images dynamically with out using data base..and want to create image for every user in my db
how to convert string to char array in java without using tochararray
how to convert string to char array in java without using tochararray ...() function. how to convert string to char array in java without using... to char array in java without using tochararray: package my.app; public
linux desktop on windows without using vn or any other ? - Java Magazine
linux desktop on windows without using vn or any other ?  linux desktop on windows without using vn or any other ?. I have a linux pc and windows... and linux are in the same network .i am trying by using using the remotedesktop
PHP Make a shoutbox without using MYSQL Tutorial
PHP Create a Shoutbox using MySQL       Make a shoutbox (mini forum) using MYSQL database. Now to make your very own PHP shoutbox, which , first of all we need to create a .html file
closing the internet explorer window of any version without confirmation using javascript
closing the internet explorer window of any version without confirmation using javascript  Hi all, Here is my requirement, I have to close microsoft internet explorer window on onload event without confirmation. It should
Hibernate's Built-in criterion: Between (using with Date)
Hibernate's Built-in criterion: Between (using with Date... to use "between" i.e.one of the built-in hibernate criterions. Restriction  class  provides built-in criterion via static factory methods. One
Closing any kind of browser window without confirmation using javascript
Closing any kind of browser window without confirmation using javascript  Here is my requirement, I have to close a browser window on onload event... version. Presently am using IE8. Thanks, Suresh
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
how to retrieve data from database using combobox value without using request.getParameter in jsp  Answer pl
how to access the object of one frame on clicking a button without using this keyword
how to access the object of one frame on clicking a button without using this keyword  import java.awt.*; import java.awt.event.*; class Mybuttons1 extends Frame { public static void main(String args[]) { Button b1
refreshing a jsp without flickering effect for every 5 seconds using ajax
refreshing a jsp without flickering effect for every 5 seconds using ajax  I want to refresh a jsp without flickering for every 5 seconds using ajax.This jsp is responsible to get the new records from the database and display
How to declare a Combobox without using a string in its declaration?
How to declare a Combobox without using a string in its declaration?  What i mean to ask is how can i declare a combobox first and initialise the values later? For example JComboBox x= new JComboBox(); ... String s={"Alpha
making consistency of data member in the whole programme without using static keyword
making consistency of data member in the whole programme without using static keyword  In the below programme i use one boolean variable named check , which is being accessed inside main function by two objects of Tst1 and Test2
How to make a CRUD without using SQL Server? by just using your GUI? (CRUD = Creating, Register, Update, Delete)
How to make a CRUD without using SQL Server? by just using your GUI? (CRUD = Creating, Register, Update, Delete)  well I got a Program that can... a CRUD again without using SQL Server. how to make it? please help
Multiple files upload code using spring mvc 2.0 with xml configuration without using annotations
Multiple files upload code using spring mvc 2.0 with xml configuration without using annotations  how to write code to attach multiple files and upload using spring mvc 2.o with xml configuration with out annotations? please
basic login and registration web page using jsp and servlet without using bean .....
basic login and registration web page using jsp and servlet without using bean .....  Hello Folks please i m totally beginner so guys please help me with very simple solution..... thnx
How to pass and catch HTML parameters to a Java program using REST services?(without using servlet/jsp)
How to pass and catch HTML parameters to a Java program using REST services?(without using servlet/jsp)  Hello, I am new to these technologies i.e.... and catch HTML parameters to a Java program using REST services?(without using
Java find prime numbers without using break statement
Java find prime numbers without using break statement In this tutorial, you will learn how to find the prime numbers without using break statement. You all are aware of Prime Numbers, these are the numbers which are either divided
i want to select a multiple value of check box by using onclick or onchange event without using from submission
i want to select a multiple value of check box by using onclick or onchange event without using from submission   i have 4 check box name 1)profile 2)commercial 3)motion 4)personal and 4 radio button name 1)500-1000 2
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array

Ads