Frequently Asked Java Program 26: How To Count Occurrences of a Character in a String

Frequently Asked Java Program 26: How To Count Occurrences of a Character in a String

SDET- QA

4 года назад

200,792 Просмотров

Topic : How To Count Occurrences of a Character in a String

#########################
Udemy Courses:
#########################

Manual Testing+Agile with Jira Tool
************************************
https://shorturl.at/xNXZ4

Selenium with Java+Cucumber
********************************
https://shorturl.at/aIKMW

Selenium with Python & PyTest
********************************
https://shorturl.at/ELW09

Selenium with python using Robot framework
****************************************
https://shorturl.at/bcDPZ

API Testing(Postman, RestAssured & SoapUI)
*****************************************
https://shorturl.at/uAWY7

Web & API Automation using Cypress with Javascript
********************************************
https://rb.gy/4uum2n

Playwright with Javascript
**************************
https://shorturl.at/gALZ1

Jmeter-Performance Testing
************************
https://rb.gy/ocj7r2

SDET Essencials(Full Stack QA)
*************************
https://rb.gy/hlnf2v

Appium-Mobile Automation Testing
************************************
https://rb.gy/wmzv64

Java Collections
*****************
https://bit.ly/3S66ezE

Python Programming
*********************
https://urlis.net/gdsfpb0s

Cucumber BDD Framework
***************************
https://bit.ly/3F7d69r

Protractor with Javascript
***************************
https://urlis.net/4uddm1qb


####################################
Youtube Playlists:
####################################

Manual Testing & Agile
***********************
https://bit.ly/3ujvaYa
https://bit.ly/3OYzxQj

SQL
*************************
https://bit.ly/3R6XjeG
https://bit.ly/3nE0a1s
https://bit.ly/3IeKuuJ

linux & Shell Scripting
**********************
https://bit.ly/3up1Z6a
https://bit.ly/3nzvGxx

Java
**********************
https://bit.ly/3R9QfOs
https://bit.ly/3AoRMKM
https://bit.ly/3IbTTDn
https://bit.ly/3ybXInv
https://bit.ly/3yCoHdw

Selenium With Java+Cucumber
********************************
https://bit.ly/3P2FMm4
https://bit.ly/3yhiIt4
https://bit.ly/3uokzet
https://bit.ly/3a7XIND
https://bit.ly/3umN2S9
https://bit.ly/3aar7GW
https://bit.ly/3y9kD2S
https://bit.ly/3uhLskn

Python
********************************
https://bit.ly/3agNgU0
https://bit.ly/3NJNnoy
https://bit.ly/2CTQ4mR
https://bit.ly/3OIYWh1

Selenium With Python,Pytest&Behave
***************************************
https://bit.ly/3OHHoC9
https://bit.ly/3IeNLdv
https://bit.ly/2J4tPeT
https://bit.ly/3ydSkAq

Selenium With Python Using Robert Framework
(Web&API Testing)
*************************************************
https://bit.ly/3nUvlpr
https://bit.ly/3nUvE3z

API Testing (Postman,SoapUi,&Rest Assured)
**********************************************
https://bit.ly/3OXacWY
https://bit.ly/3yh0UhE
https://bit.ly/3nC9DWQ
https://bit.ly/3yGfhNS
https://bit.ly/3OJa11H
https://bit.ly/3P2slCC

Mobile App Testing Appium
****************************
https://bit.ly/3Al49HG

Performance Testing Jmeter
*******************************
https://bit.ly/3nz4fE7

Maven,Jenkins,Git,Github,CI/CD
*******************************
https://bit.ly/3P16HPj
https://bit.ly/3yhlUVA
https://bit.ly/3afYfwT
https://bit.ly/3yGzweG
https://bit.ly/3yF73Ws
https://bit.ly/3NCOmH7

SQL,DB Testing&ETL,Bigdata
*******************************
https://bit.ly/3NKOcNY
https://bit.ly/3OVpDyI
https://bit.ly/3NEvUy0
https://bit.ly/3IryxlT
https://bit.ly/3RkWBLh

JavaScript Based Automation Tools
********************************
https://bit.ly/3nUx51X
https://bit.ly/3AqI6Q0
https://bit.ly/3yeurbT
https://bit.ly/3ujzpTK

Selector Hub Tools
********************
https://rb.gy/h3h424

GraphQL
******************
https://rb.gy/sj3gys

Cypress API Testing
********************
https://shorturl.at/fjKPX

Cypress Web Testing
**********************
https://shorturl.at/agjlK

Playwright with Javascipt
**************************
https://shorturl.at/adSTY

#PythonStringOccurrences
#CharCountInString
#StringCharacterFrequency
#CountCharsPython
#StringManipulation
#PythonProgramming
#CodingChallenge
#StringOperations
#PythonTips
#ProgrammingLogic
#CodingInPython
#StringParsing
#CharacterFrequency
#CodingSolutions
#StringManipulation
#PythonProblems
#AlgorithmPractice
#CodingSkills
#StringHandling
#TechInterview
#PythonCoding
#CodeSnippet
#CodingCommunity
#ProgrammingHelp
#PythonBeginner
#StringAlgorithms
#CodeLogic
#LearnPython
#CodingFundamentals
#ProgrammingTips
#CodeEfficiency
#PythonTricks
#AlgorithmDesign
#StringSearch
#ProblemSolving
#PythonTrickery
#CodeOptimization
#PythonLogic
#StringParsing
#AlgorithmExplained
#PythonLearning
#CodeBreakdown
#ProgrammingCommunity
#TechSolutions
#PythonSnippets
#CodingExplained
#StringTraversal
#PythonExperts
#CodeWalkthrough
#PythonMastery

Тэги:

#Python #Selenium_with_Python #Selenium_webdriver #Automation #Testing_tools #Selenium_tutorials #Python_tutorials #Manual_testing #SDET #Java #selenium_with_java #big_data #hadoop #web_services #postman #soapui #rest_assured #SQL #Programming #Software_Testing_material #selenium_videos #python_videos #automation_vidios #jira #jmeter #performance_testing #functional_testing #QA #QC #Agile_testing #SDLC #Automation_Step_by_Step #restapi #Count_Occurrences_of_a_Character_in_a_String
Ссылки и html тэги не поддерживаются


Комментарии:

@user-ni4bo4pi8p
@user-ni4bo4pi8p - 24.11.2023 03:24

Superb easy to understand sir...thanks a lot for helping us.

Ответить
@tejajami6729
@tejajami6729 - 19.11.2023 08:50

import java.util.Arrays;

class OccrenceOfInputArray {

public static void main(String[] args) {
int arr[] = {1, 1, 2, 2, 3, 4, 5, 6, 8, 9};
int len = arr.length;
System.out.println("Total length: " + len);

String arrString = Arrays.toString(arr);

// Replace '2' with an empty string and get the length
int totalCount = len - arrString.replace("2", "").length();
System.out.println("Total count of 2: " + totalCount);
}
}



sir, while im running this program after removing the 2 we got the output is 8, but here output is getting is: -18..........please clarify this doubt sir

Ответить
@ananya8672
@ananya8672 - 23.10.2023 11:09

not a good approach

Ответить
@kvelez
@kvelez - 26.09.2023 04:37

import java.util.HashMap;
import java.util.Scanner;

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

System.out.print("\nEnter a statement: ");
Scanner scan = new Scanner(System.in);
String statement = scan.nextLine();
scan.close();

String[] words = statement.split("\\s+");
HashMap<String, Integer> wordHashMap = new HashMap<>();
HashMap<Character, Integer> letterHashMap = new HashMap<>();

for (int i = 0; i < statement.length(); i++){
char currentChar = statement.charAt(i);
if (letterHashMap.containsKey(currentChar)){
letterHashMap.put(currentChar, letterHashMap.get(currentChar) + 1);
} else {
letterHashMap.put(currentChar, 1);
}
}

for (Character letter : letterHashMap.keySet()){
int count = letterHashMap.get(letter);
System.out.println("Letter: " + letter + " appears " + count + " times.");
}

for (String word : words){

if (wordHashMap.containsKey(word)){
wordHashMap.put(word, wordHashMap.get(word) + 1);
} else {
wordHashMap.put(word, 1);
}

}

for (String item : wordHashMap.keySet()){
int count = wordHashMap.get(item);
System.out.println("Word: " + item + " appears: " + count + " times.");
}

}
}

Ответить
@subhojitbiswas3876
@subhojitbiswas3876 - 21.09.2023 10:50

I think string.chatAT(i) ==letter and count ++ will do the job right

Ответить
@emmadivamshi1798
@emmadivamshi1798 - 25.08.2023 21:20

Sir Your explanation is very nice and am very thankful to you sir

Ответить
@vikramsinghyadav7793
@vikramsinghyadav7793 - 18.07.2023 19:57

Sir we can use Hashmap that would be more efficient

Ответить
@nayabshaik2282
@nayabshaik2282 - 11.07.2023 19:33

I was very scary to make understand coding earlier. But once I started watching your videos, my thought process changed.
I am very comfortable to understand your logics, I feel like "OH CODING IS SUCH SIMPLE" 😄🤣
Great Thank you Pavan sir..🤝🤝🙏🙏

Ответить
@user-rr8wh2oe5e
@user-rr8wh2oe5e - 22.05.2023 10:59

hi sir can we use this method is scanner sirif yes can u tell me how to use it

Ответить
@Himu421
@Himu421 - 28.03.2023 22:39

Amazing video sir ! You code in such simple way and explain it so well that any basic /intermediate base person can fully grasp the concept and learn coding.

Ответить
@shubhammane4579
@shubhammane4579 - 20.03.2023 18:28

Thank You Sir... You Make My Logic Building Strong... Simple And Up to The Mark Explanation...😇🙏

Ответить
@gayathridhana1000
@gayathridhana1000 - 09.03.2023 09:57

sir please make more interview programs

Ответить
@shraddhaprabhu9033
@shraddhaprabhu9033 - 26.02.2023 13:11

Sir make program video of duplicate characters in a string

Ответить
@yashtarale7891
@yashtarale7891 - 19.02.2023 16:54

why writing this much complex...i dont know............

we can write in this way too

String s="yash is a good boy ";
char comp='a';
int flag=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)==comp){
flag++;
}
}
System.out.println(flag);

Ответить
@NiteshKumar-vz8uy
@NiteshKumar-vz8uy - 18.01.2023 17:56

This question asked me today

Ответить
@rizwanreshi8673
@rizwanreshi8673 - 13.12.2022 20:24

Sir what about when there are same letter with upper and lower case.

Ответить
@krishdeepika6967
@krishdeepika6967 - 09.12.2022 09:19

Not working giving output as zero

Ответить
@v2factsandupdates327
@v2factsandupdates327 - 16.11.2022 20:11

Excellent explanation

Ответить
@shubhamrakshe6478
@shubhamrakshe6478 - 29.08.2022 20:50

this is easiest program i have seen ..thanks sir

Ответить
@groundlevel1817
@groundlevel1817 - 09.08.2022 13:03

impressive.

Ответить
@rameshtirneddi5624
@rameshtirneddi5624 - 14.07.2022 04:44

if we get string from the user then how to get max occuring character

Ответить
@bidya74
@bidya74 - 08.03.2022 19:06

corrupted

Ответить
@MAGAVISHNUT
@MAGAVISHNUT - 06.03.2022 09:54

This for known statement.. Then what is code for when we use scanner Class

Ответить
@magicalmagie2889
@magicalmagie2889 - 26.02.2022 09:17

Sir y u removing a es

Ответить
@zishanalam8277
@zishanalam8277 - 10.02.2022 19:43

What about no case sensitive

Ответить
@ravindrakawale5161
@ravindrakawale5161 - 16.11.2021 07:52

Great explain....🙌🙌

Ответить
@udaybenake206
@udaybenake206 - 16.10.2021 09:05

This is working but does not count uppercase characters if we are pass lowercase or vice versa

Ответить
@shakulhameed1767
@shakulhameed1767 - 04.10.2021 18:18

we simply sovle the problem like
int count =s.replaceAll("[^a]","").length();

Ответить
@hemrajpatil782
@hemrajpatil782 - 02.10.2021 10:43

very easy sir.thank u. sir can u please make programm for prime no. from array ..please sir .

Ответить
@swayamprakashbhuyan2580
@swayamprakashbhuyan2580 - 19.08.2021 23:51

Love your videos and commenting for better reach. You have a great voice btw.

Ответить
@vs4084
@vs4084 - 06.07.2021 17:06

Thankyou sir for this video...

Ответить
@Canada1989
@Canada1989 - 04.07.2021 00:56

This was asked in my interview

Ответить
Ayudh Singh
Ayudh Singh - 20.11.2020 16:14

Tell for all character occurences. For all occurences it will become a very exhausting code

Ответить
@abinayabala6868
@abinayabala6868 - 20.10.2020 17:57

can u tell me how to check for all the character occurence

Ответить
@aryanbhavsar7067
@aryanbhavsar7067 - 07.10.2020 18:12

this method is also easy check it guys'
String str="java programming is very easy";
int count=0;


for(int i=0;i<str.length();i++) {
if(str.charAt(i)=='a') {
count++;
}
}


System.out.println("number of occurances letter a :"+count);
try this one also easy and thank u sir for these videos

Ответить
@vithvishnu1497
@vithvishnu1497 - 14.09.2020 21:33

Can i get this in loop.. if yes can u comment the statement..

Ответить
@MB-zt7cd
@MB-zt7cd - 04.07.2020 06:10

Nice explanation however I am bit confused, as we count the spaces as well in index., So when we are replacing a with space, the space would still be counted. so not sure how did it work. Could you please explain the logic for that. Thank you

Ответить
@pakkaandhrapori3768
@pakkaandhrapori3768 - 27.06.2020 16:38

Thanks for easy explanation and can we do the same program without "replace" method? please explain the approach as well

Ответить
@iliveinacrowdedhouse368
@iliveinacrowdedhouse368 - 12.05.2020 02:50

Bonne vidéo

Ответить
@kvnagendra5354
@kvnagendra5354 - 12.02.2020 14:32

Nice explanation

Ответить