0% found this document useful (0 votes)
4 views3 pages

String Manipulation Functions

The document outlines a series of static methods for string manipulation in Java, including counting words, spaces, characters, and vowels, as well as reversing strings and checking for palindromes. It also includes methods for trimming spaces, changing case, and finding anagrams. Additionally, there are methods for generating triangles of strings, counting frequencies, and handling binary to decimal conversions.

Uploaded by

vansh4242sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

String Manipulation Functions

The document outlines a series of static methods for string manipulation in Java, including counting words, spaces, characters, and vowels, as well as reversing strings and checking for palindromes. It also includes methods for trimming spaces, changing case, and finding anagrams. Additionally, there are methods for generating triangles of strings, counting frequencies, and handling binary to decimal conversions.

Uploaded by

vansh4242sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

1) static int wordCount(String s)

2) static int spaceCount(String s)

3) static int charCount(String s) //without spaces

4) static String reverse(String g)//dont use reverse() function of StringBuffer

5) static boolean palindrome(String s)

6) static String ITrim(String s) //remove left spaces //dont use trim() function

7) static String rTrim(String s) //remove right spaces //dont use trim() function

8) static String allTrim(String s) //equivalent to trim() //dont use trim()


function

9) static String squeeze(String s) //remove all spaces and convert whole String in
one word

10)static int vowelCount(String s)

11)static int length(String s)//dont use length() function

12)static void sequenceCount(String s)

13)static void frequencyCount(String) //print frequency wise order

14)static String changeCase(string s) //InDla => iNdiA

15)static String singleOccurence(String s) //nniittiiin => nitin

16)static void sortedOrder(String s)//manish-->ahimns

17)static String sortedWord(String)//india aus china japan-->aus china india japan

18)static boolean find(String s1, String s2) //s2 in s1 dont use indexOf()and
lastIndexOf() function

19)static String replace(String s1, String s2, String s3) //if s2 is found in s1,
replace s2 with s3

20)static boolean equals(String s1, String s2)//dont use equals() function

21)static void triangle1 (String s1){


a
ap
app
apps
appsq
appsqu
appsqua
appsquad
appsquadz
}

22)static void triangle2 (String s1){


appsquadz
appsquad
appsqua
appsqu
appsq
apps
app
ap
a
}

23)static void triangle3 (String s1){


appsquadz
ppsquadz
psquadz
squadz
quadz
uadz
adz
dz
z
}

24)static void triangle2 (String s1){


appsquadzappsquadz
appsquad ppsquadz
appsqua psquadz
appsqu squadz
appsq quadz
apps uadz
app adz
ap dz
a z
}

25)static int compare(String s1, String s2)//dont use compareTo() function

26)public static void wordFrequencyCount(String s1) count the frequency of each


word in a string

27)solve the string


public int expression("10+20+20+20")

28)public int Binary ToDecimal("10101010")

29)public void printNonRepetingFirstChar(String s)

30)public void reverseEachWord(String s)//india usa china->aidni asu anihc

31)public void printAllWordsInReverseOrder(String s)//india usa china->china usa


india

32)boolean findDigitInString(String s)

33)int countDigitInString(String s)

34)Write down a program to find biggest substring in between specified character or


string
eg i am rajesh kumar ravi
in between 'a'
35)DOG >print all the combination of this word

36)find the largest palindrom in a String.//nitin madam malayalam

37)count the percentage of small letters, Capital letters and special characters in
String
"abcdeHIJLLM@@@::...."

38)Given two strings s1 and s2 consisting of lowercase characters, the task is to


check whether the two given
strings are anagrams of each other or not. An anagram of a string is another
string that contains the same
characters, only the order of characters can be different. For example, "act"
and "tac" are anagrams of each other.

Examples:
Input: str1 ="listen" str2 ="silent"
Output: "Anagram"
Explanation: All characters of "listen" and "silent" are the same.

Input: str1 = "gram" str2 = "arm"


Output: "Not Anagram"

Common questions

Powered by AI

To count the frequency of each word in a string, `public static void wordFrequencyCount(String s1)` should split the string into words using a delimiter like space, store each word in a map, and then iterate over the array incrementing the count for each word encountered in the map .

To arrange characters in lexicographical order, `static void sortedOrder(String s)` can be implemented. This involves converting the string into a character array, applying a sorting algorithm such as bubble sort or merge sort, and reconstructing the sorted string from the character array .

The method `static String changeCase(String s)` converts each character to its opposite case by iterating over the string, checking if it's uppercase or lowercase, and changing appropriately to toggle the case for each character without using built-in case functions .

To find the largest palindrome in a string, iterate through all possible substrings, check each substring using a method similar to `palindrome(String s)`, and update the record for the longest one found during these checks .

The method `static String allTrim(String s)` can be used to trim spaces from both ends of a string. It requires creating custom functions such as `ITrim` to remove leading spaces and `rTrim` for trailing spaces. Combining these functions will provide a complete trimming effect equivalent to `trim()` .

To determine if a string is a palindrome without using built-in functions, a method `static boolean palindrome(String s)` can be used by comparing characters from the start and the end of the string moving towards the center. If all corresponding characters match, the string is a palindrome, otherwise, it is not .

To calculate the character count of a string without including spaces, one can implement a method such as `static int charCount(String s)` which iterates through each character in the string and increments a counter only if the character is not a space. This approach ensures spaces are excluded from the count .

For replacing a substring within a string without using built-in index functions, `static String replace(String s1, String s2, String s3)` involves manually searching for the substring using a loop, checking for matching starting positions, and performing the replacement by constructing the new string with the modified content .

For reversing each word individually in a string, use the method `public void reverseEachWord(String s)`, which splits the string into words, reverses each word independently, and joins them back together with spaces separating them. This word-by-word manipulation ensures each word is reversed while maintaining their order .

To check if two strings are anagrams, `compare(String s1, String s2)` sorts both strings and compares the sorted results. Anagrams will match exactly in their sorted forms. Alternatively, character count comparisons can be used to verify each character's frequency in both strings .

You might also like