how to count the number of alphabet in a pdf file in java












0















In this program, I need to count the number of all alphabets (a-z) and the code below is only able to count the number of "u". So if I want to count 26 of it, do I need to write 26 if statement in the for loop?



the output should be:
a:389
b:777
c:909
..
..



Please give me other solution



            String words = sourceCode.split(" ");
amountOfWords = amountOfWords + words.length;
for (String word : words) {
amountOfChars = amountOfChars + word.length();

for (int i = 0; i < word.length(); i++) {
if (word.charAt(i) == 'u' || word.charAt(i) == 'U') {
u++;
}
}
}









share|improve this question

























  • Please look at the word count questions here on SO, e.g. stackoverflow.com/questions/29122394/… It's basically the same, just do it for the characters, i.e. flatMap each word to the chars in an additional step.

    – AKSW
    Nov 23 '18 at 7:22













  • Possible duplicate of Checking for Alphabets in a String in java

    – Arnaud
    Nov 23 '18 at 7:26
















0















In this program, I need to count the number of all alphabets (a-z) and the code below is only able to count the number of "u". So if I want to count 26 of it, do I need to write 26 if statement in the for loop?



the output should be:
a:389
b:777
c:909
..
..



Please give me other solution



            String words = sourceCode.split(" ");
amountOfWords = amountOfWords + words.length;
for (String word : words) {
amountOfChars = amountOfChars + word.length();

for (int i = 0; i < word.length(); i++) {
if (word.charAt(i) == 'u' || word.charAt(i) == 'U') {
u++;
}
}
}









share|improve this question

























  • Please look at the word count questions here on SO, e.g. stackoverflow.com/questions/29122394/… It's basically the same, just do it for the characters, i.e. flatMap each word to the chars in an additional step.

    – AKSW
    Nov 23 '18 at 7:22













  • Possible duplicate of Checking for Alphabets in a String in java

    – Arnaud
    Nov 23 '18 at 7:26














0












0








0








In this program, I need to count the number of all alphabets (a-z) and the code below is only able to count the number of "u". So if I want to count 26 of it, do I need to write 26 if statement in the for loop?



the output should be:
a:389
b:777
c:909
..
..



Please give me other solution



            String words = sourceCode.split(" ");
amountOfWords = amountOfWords + words.length;
for (String word : words) {
amountOfChars = amountOfChars + word.length();

for (int i = 0; i < word.length(); i++) {
if (word.charAt(i) == 'u' || word.charAt(i) == 'U') {
u++;
}
}
}









share|improve this question
















In this program, I need to count the number of all alphabets (a-z) and the code below is only able to count the number of "u". So if I want to count 26 of it, do I need to write 26 if statement in the for loop?



the output should be:
a:389
b:777
c:909
..
..



Please give me other solution



            String words = sourceCode.split(" ");
amountOfWords = amountOfWords + words.length;
for (String word : words) {
amountOfChars = amountOfChars + word.length();

for (int i = 0; i < word.length(); i++) {
if (word.charAt(i) == 'u' || word.charAt(i) == 'U') {
u++;
}
}
}






java count pdfbox






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 12:01







Choy

















asked Nov 23 '18 at 7:20









Choy Choy

598




598













  • Please look at the word count questions here on SO, e.g. stackoverflow.com/questions/29122394/… It's basically the same, just do it for the characters, i.e. flatMap each word to the chars in an additional step.

    – AKSW
    Nov 23 '18 at 7:22













  • Possible duplicate of Checking for Alphabets in a String in java

    – Arnaud
    Nov 23 '18 at 7:26



















  • Please look at the word count questions here on SO, e.g. stackoverflow.com/questions/29122394/… It's basically the same, just do it for the characters, i.e. flatMap each word to the chars in an additional step.

    – AKSW
    Nov 23 '18 at 7:22













  • Possible duplicate of Checking for Alphabets in a String in java

    – Arnaud
    Nov 23 '18 at 7:26

















Please look at the word count questions here on SO, e.g. stackoverflow.com/questions/29122394/… It's basically the same, just do it for the characters, i.e. flatMap each word to the chars in an additional step.

– AKSW
Nov 23 '18 at 7:22







Please look at the word count questions here on SO, e.g. stackoverflow.com/questions/29122394/… It's basically the same, just do it for the characters, i.e. flatMap each word to the chars in an additional step.

– AKSW
Nov 23 '18 at 7:22















Possible duplicate of Checking for Alphabets in a String in java

– Arnaud
Nov 23 '18 at 7:26





Possible duplicate of Checking for Alphabets in a String in java

– Arnaud
Nov 23 '18 at 7:26












2 Answers
2






active

oldest

votes


















1














You can try this. I am using library : fontbox-2.0.12 and pdfbox-2.0.12 and commons-logging-1.2



        try {
PDDocument doc = PDDocument.load(new File("E:\project-test\scloud\test\src\main\resources\Shadip_Banik.pdf"));
String text = new PDFTextStripper().getText(doc);

sourceCode = text.replace("-", "").replace(".", "");


String words = sourceCode.split(" ");

amountOfWords = amountOfWords + words.length;
StringBuilder builder = new StringBuilder();

for (String word : words) {
amountOfChars = amountOfChars + word.length();

Pattern pattern = Pattern.compile("[a-zA-Z]");
Matcher matcher = pattern.matcher(word);
//System.out.println("MatchesCount "+matcher.group());
while (matcher.find()) {
builder.append(matcher.group());

}
}
String allData = builder.toString();
System.out.println(builder.toString());
int total = 0;
for (int i=0;i<allAlphabate.length();i++)
{
int alphabateCount = 0;
Pattern pattern = Pattern.compile(Character.toString(allAlphabate.charAt(i)));
Matcher matcher = pattern.matcher(allData);
while (matcher.find()) {
alphabateCount++;
}
total+=alphabateCount;
System.out.println(allAlphabate.charAt(i) +" : "+alphabateCount);
}
if(total == builder.toString().length())
{
System.out.println("Yes -------------------------------------------------");
}
System.out.println("Amount of Chars is " + amountOfChars);
System.out.println("Amount of Words is " + (amountOfWords + 1));
System.out.println("Average Word Length is " + (amountOfChars / amountOfWords));
} catch (Exception ert) {

}


But If you want to calculate uppercase and lowercase together use this code



     for (String word : words) {
amountOfChars = amountOfChars + word.length();

Pattern pattern = Pattern.compile("[a-zA-Z]");
Matcher matcher = pattern.matcher(word.toLowerCase());
//System.out.println("MatchesCount "+matcher.group());
while (matcher.find()) {
builder.append(matcher.group());

}
}
String allData = builder.toString();
int total = 0;
for (int i=0;i<allAlphabate.length();i++)
{
int alphabateCount = 0;
Pattern pattern = Pattern.compile(Character.toString(allAlphabate.charAt(i)));
Matcher matcher = pattern.matcher(allData.toLowerCase());
while (matcher.find()) {
alphabateCount++;
}
total+=alphabateCount;
System.out.println(allAlphabate.charAt(i) +" : "+alphabateCount);
}
if(total == builder.toString().length())
{
System.out.println("Yes -------------------------------------------------");
}





share|improve this answer





















  • 1





    the output is weird, it calculates the word occur how many times, not alphabet(a-z)

    – Choy
    Nov 23 '18 at 9:24











  • Check now. Probably it will that you desire

    – flopcoder
    Nov 23 '18 at 9:34











  • yaya, it looks what I want now, but these codes didn't count uppercase and lowercase together, right?

    – Choy
    Nov 23 '18 at 9:45











  • its calculate uppercase and lowercase toghether. you can do it some change on this code

    – flopcoder
    Nov 23 '18 at 9:46













  • change this to String allAlphabate = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; and then remove tolowercase function in sevaral places

    – flopcoder
    Nov 23 '18 at 9:48



















0














try this:



String str = new PDFTextStripper().getText(doc);    
int len = str.length();
Map<Character, Integer> numOfChars = new HashMap<Character, Integer>(Math.min(len, 26));

for (int i = 0; i < len; ++i)//pre increment
{
char alphabet = str.charAt(i);
if (!numOfChars.containsKey(alphabet ))
{
numOfChars.put(alphabet , 1);
}
else
{
numOfChars.put(alphabet , numOfChars.get(alphabet ) + 1);
}
}
System.out.println(numOfChars);


Source






share|improve this answer
























  • these code basically print not only alphabet, it print symbol also like "=9, !=2

    – Choy
    Nov 23 '18 at 9:26











  • @Choy it is giving output like this {a=3, s=1, d=1, w=1, h=1, i=2, m=1, n=4} what else do you want?

    – nimi0112
    Nov 23 '18 at 10:12













  • no the output contain others else

    – Choy
    Nov 23 '18 at 10:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442215%2fhow-to-count-the-number-of-alphabet-in-a-pdf-file-in-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can try this. I am using library : fontbox-2.0.12 and pdfbox-2.0.12 and commons-logging-1.2



        try {
PDDocument doc = PDDocument.load(new File("E:\project-test\scloud\test\src\main\resources\Shadip_Banik.pdf"));
String text = new PDFTextStripper().getText(doc);

sourceCode = text.replace("-", "").replace(".", "");


String words = sourceCode.split(" ");

amountOfWords = amountOfWords + words.length;
StringBuilder builder = new StringBuilder();

for (String word : words) {
amountOfChars = amountOfChars + word.length();

Pattern pattern = Pattern.compile("[a-zA-Z]");
Matcher matcher = pattern.matcher(word);
//System.out.println("MatchesCount "+matcher.group());
while (matcher.find()) {
builder.append(matcher.group());

}
}
String allData = builder.toString();
System.out.println(builder.toString());
int total = 0;
for (int i=0;i<allAlphabate.length();i++)
{
int alphabateCount = 0;
Pattern pattern = Pattern.compile(Character.toString(allAlphabate.charAt(i)));
Matcher matcher = pattern.matcher(allData);
while (matcher.find()) {
alphabateCount++;
}
total+=alphabateCount;
System.out.println(allAlphabate.charAt(i) +" : "+alphabateCount);
}
if(total == builder.toString().length())
{
System.out.println("Yes -------------------------------------------------");
}
System.out.println("Amount of Chars is " + amountOfChars);
System.out.println("Amount of Words is " + (amountOfWords + 1));
System.out.println("Average Word Length is " + (amountOfChars / amountOfWords));
} catch (Exception ert) {

}


But If you want to calculate uppercase and lowercase together use this code



     for (String word : words) {
amountOfChars = amountOfChars + word.length();

Pattern pattern = Pattern.compile("[a-zA-Z]");
Matcher matcher = pattern.matcher(word.toLowerCase());
//System.out.println("MatchesCount "+matcher.group());
while (matcher.find()) {
builder.append(matcher.group());

}
}
String allData = builder.toString();
int total = 0;
for (int i=0;i<allAlphabate.length();i++)
{
int alphabateCount = 0;
Pattern pattern = Pattern.compile(Character.toString(allAlphabate.charAt(i)));
Matcher matcher = pattern.matcher(allData.toLowerCase());
while (matcher.find()) {
alphabateCount++;
}
total+=alphabateCount;
System.out.println(allAlphabate.charAt(i) +" : "+alphabateCount);
}
if(total == builder.toString().length())
{
System.out.println("Yes -------------------------------------------------");
}





share|improve this answer





















  • 1





    the output is weird, it calculates the word occur how many times, not alphabet(a-z)

    – Choy
    Nov 23 '18 at 9:24











  • Check now. Probably it will that you desire

    – flopcoder
    Nov 23 '18 at 9:34











  • yaya, it looks what I want now, but these codes didn't count uppercase and lowercase together, right?

    – Choy
    Nov 23 '18 at 9:45











  • its calculate uppercase and lowercase toghether. you can do it some change on this code

    – flopcoder
    Nov 23 '18 at 9:46













  • change this to String allAlphabate = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; and then remove tolowercase function in sevaral places

    – flopcoder
    Nov 23 '18 at 9:48
















1














You can try this. I am using library : fontbox-2.0.12 and pdfbox-2.0.12 and commons-logging-1.2



        try {
PDDocument doc = PDDocument.load(new File("E:\project-test\scloud\test\src\main\resources\Shadip_Banik.pdf"));
String text = new PDFTextStripper().getText(doc);

sourceCode = text.replace("-", "").replace(".", "");


String words = sourceCode.split(" ");

amountOfWords = amountOfWords + words.length;
StringBuilder builder = new StringBuilder();

for (String word : words) {
amountOfChars = amountOfChars + word.length();

Pattern pattern = Pattern.compile("[a-zA-Z]");
Matcher matcher = pattern.matcher(word);
//System.out.println("MatchesCount "+matcher.group());
while (matcher.find()) {
builder.append(matcher.group());

}
}
String allData = builder.toString();
System.out.println(builder.toString());
int total = 0;
for (int i=0;i<allAlphabate.length();i++)
{
int alphabateCount = 0;
Pattern pattern = Pattern.compile(Character.toString(allAlphabate.charAt(i)));
Matcher matcher = pattern.matcher(allData);
while (matcher.find()) {
alphabateCount++;
}
total+=alphabateCount;
System.out.println(allAlphabate.charAt(i) +" : "+alphabateCount);
}
if(total == builder.toString().length())
{
System.out.println("Yes -------------------------------------------------");
}
System.out.println("Amount of Chars is " + amountOfChars);
System.out.println("Amount of Words is " + (amountOfWords + 1));
System.out.println("Average Word Length is " + (amountOfChars / amountOfWords));
} catch (Exception ert) {

}


But If you want to calculate uppercase and lowercase together use this code



     for (String word : words) {
amountOfChars = amountOfChars + word.length();

Pattern pattern = Pattern.compile("[a-zA-Z]");
Matcher matcher = pattern.matcher(word.toLowerCase());
//System.out.println("MatchesCount "+matcher.group());
while (matcher.find()) {
builder.append(matcher.group());

}
}
String allData = builder.toString();
int total = 0;
for (int i=0;i<allAlphabate.length();i++)
{
int alphabateCount = 0;
Pattern pattern = Pattern.compile(Character.toString(allAlphabate.charAt(i)));
Matcher matcher = pattern.matcher(allData.toLowerCase());
while (matcher.find()) {
alphabateCount++;
}
total+=alphabateCount;
System.out.println(allAlphabate.charAt(i) +" : "+alphabateCount);
}
if(total == builder.toString().length())
{
System.out.println("Yes -------------------------------------------------");
}





share|improve this answer





















  • 1





    the output is weird, it calculates the word occur how many times, not alphabet(a-z)

    – Choy
    Nov 23 '18 at 9:24











  • Check now. Probably it will that you desire

    – flopcoder
    Nov 23 '18 at 9:34











  • yaya, it looks what I want now, but these codes didn't count uppercase and lowercase together, right?

    – Choy
    Nov 23 '18 at 9:45











  • its calculate uppercase and lowercase toghether. you can do it some change on this code

    – flopcoder
    Nov 23 '18 at 9:46













  • change this to String allAlphabate = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; and then remove tolowercase function in sevaral places

    – flopcoder
    Nov 23 '18 at 9:48














1












1








1







You can try this. I am using library : fontbox-2.0.12 and pdfbox-2.0.12 and commons-logging-1.2



        try {
PDDocument doc = PDDocument.load(new File("E:\project-test\scloud\test\src\main\resources\Shadip_Banik.pdf"));
String text = new PDFTextStripper().getText(doc);

sourceCode = text.replace("-", "").replace(".", "");


String words = sourceCode.split(" ");

amountOfWords = amountOfWords + words.length;
StringBuilder builder = new StringBuilder();

for (String word : words) {
amountOfChars = amountOfChars + word.length();

Pattern pattern = Pattern.compile("[a-zA-Z]");
Matcher matcher = pattern.matcher(word);
//System.out.println("MatchesCount "+matcher.group());
while (matcher.find()) {
builder.append(matcher.group());

}
}
String allData = builder.toString();
System.out.println(builder.toString());
int total = 0;
for (int i=0;i<allAlphabate.length();i++)
{
int alphabateCount = 0;
Pattern pattern = Pattern.compile(Character.toString(allAlphabate.charAt(i)));
Matcher matcher = pattern.matcher(allData);
while (matcher.find()) {
alphabateCount++;
}
total+=alphabateCount;
System.out.println(allAlphabate.charAt(i) +" : "+alphabateCount);
}
if(total == builder.toString().length())
{
System.out.println("Yes -------------------------------------------------");
}
System.out.println("Amount of Chars is " + amountOfChars);
System.out.println("Amount of Words is " + (amountOfWords + 1));
System.out.println("Average Word Length is " + (amountOfChars / amountOfWords));
} catch (Exception ert) {

}


But If you want to calculate uppercase and lowercase together use this code



     for (String word : words) {
amountOfChars = amountOfChars + word.length();

Pattern pattern = Pattern.compile("[a-zA-Z]");
Matcher matcher = pattern.matcher(word.toLowerCase());
//System.out.println("MatchesCount "+matcher.group());
while (matcher.find()) {
builder.append(matcher.group());

}
}
String allData = builder.toString();
int total = 0;
for (int i=0;i<allAlphabate.length();i++)
{
int alphabateCount = 0;
Pattern pattern = Pattern.compile(Character.toString(allAlphabate.charAt(i)));
Matcher matcher = pattern.matcher(allData.toLowerCase());
while (matcher.find()) {
alphabateCount++;
}
total+=alphabateCount;
System.out.println(allAlphabate.charAt(i) +" : "+alphabateCount);
}
if(total == builder.toString().length())
{
System.out.println("Yes -------------------------------------------------");
}





share|improve this answer















You can try this. I am using library : fontbox-2.0.12 and pdfbox-2.0.12 and commons-logging-1.2



        try {
PDDocument doc = PDDocument.load(new File("E:\project-test\scloud\test\src\main\resources\Shadip_Banik.pdf"));
String text = new PDFTextStripper().getText(doc);

sourceCode = text.replace("-", "").replace(".", "");


String words = sourceCode.split(" ");

amountOfWords = amountOfWords + words.length;
StringBuilder builder = new StringBuilder();

for (String word : words) {
amountOfChars = amountOfChars + word.length();

Pattern pattern = Pattern.compile("[a-zA-Z]");
Matcher matcher = pattern.matcher(word);
//System.out.println("MatchesCount "+matcher.group());
while (matcher.find()) {
builder.append(matcher.group());

}
}
String allData = builder.toString();
System.out.println(builder.toString());
int total = 0;
for (int i=0;i<allAlphabate.length();i++)
{
int alphabateCount = 0;
Pattern pattern = Pattern.compile(Character.toString(allAlphabate.charAt(i)));
Matcher matcher = pattern.matcher(allData);
while (matcher.find()) {
alphabateCount++;
}
total+=alphabateCount;
System.out.println(allAlphabate.charAt(i) +" : "+alphabateCount);
}
if(total == builder.toString().length())
{
System.out.println("Yes -------------------------------------------------");
}
System.out.println("Amount of Chars is " + amountOfChars);
System.out.println("Amount of Words is " + (amountOfWords + 1));
System.out.println("Average Word Length is " + (amountOfChars / amountOfWords));
} catch (Exception ert) {

}


But If you want to calculate uppercase and lowercase together use this code



     for (String word : words) {
amountOfChars = amountOfChars + word.length();

Pattern pattern = Pattern.compile("[a-zA-Z]");
Matcher matcher = pattern.matcher(word.toLowerCase());
//System.out.println("MatchesCount "+matcher.group());
while (matcher.find()) {
builder.append(matcher.group());

}
}
String allData = builder.toString();
int total = 0;
for (int i=0;i<allAlphabate.length();i++)
{
int alphabateCount = 0;
Pattern pattern = Pattern.compile(Character.toString(allAlphabate.charAt(i)));
Matcher matcher = pattern.matcher(allData.toLowerCase());
while (matcher.find()) {
alphabateCount++;
}
total+=alphabateCount;
System.out.println(allAlphabate.charAt(i) +" : "+alphabateCount);
}
if(total == builder.toString().length())
{
System.out.println("Yes -------------------------------------------------");
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 12:11

























answered Nov 23 '18 at 9:08









flopcoderflopcoder

745512




745512








  • 1





    the output is weird, it calculates the word occur how many times, not alphabet(a-z)

    – Choy
    Nov 23 '18 at 9:24











  • Check now. Probably it will that you desire

    – flopcoder
    Nov 23 '18 at 9:34











  • yaya, it looks what I want now, but these codes didn't count uppercase and lowercase together, right?

    – Choy
    Nov 23 '18 at 9:45











  • its calculate uppercase and lowercase toghether. you can do it some change on this code

    – flopcoder
    Nov 23 '18 at 9:46













  • change this to String allAlphabate = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; and then remove tolowercase function in sevaral places

    – flopcoder
    Nov 23 '18 at 9:48














  • 1





    the output is weird, it calculates the word occur how many times, not alphabet(a-z)

    – Choy
    Nov 23 '18 at 9:24











  • Check now. Probably it will that you desire

    – flopcoder
    Nov 23 '18 at 9:34











  • yaya, it looks what I want now, but these codes didn't count uppercase and lowercase together, right?

    – Choy
    Nov 23 '18 at 9:45











  • its calculate uppercase and lowercase toghether. you can do it some change on this code

    – flopcoder
    Nov 23 '18 at 9:46













  • change this to String allAlphabate = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; and then remove tolowercase function in sevaral places

    – flopcoder
    Nov 23 '18 at 9:48








1




1





the output is weird, it calculates the word occur how many times, not alphabet(a-z)

– Choy
Nov 23 '18 at 9:24





the output is weird, it calculates the word occur how many times, not alphabet(a-z)

– Choy
Nov 23 '18 at 9:24













Check now. Probably it will that you desire

– flopcoder
Nov 23 '18 at 9:34





Check now. Probably it will that you desire

– flopcoder
Nov 23 '18 at 9:34













yaya, it looks what I want now, but these codes didn't count uppercase and lowercase together, right?

– Choy
Nov 23 '18 at 9:45





yaya, it looks what I want now, but these codes didn't count uppercase and lowercase together, right?

– Choy
Nov 23 '18 at 9:45













its calculate uppercase and lowercase toghether. you can do it some change on this code

– flopcoder
Nov 23 '18 at 9:46







its calculate uppercase and lowercase toghether. you can do it some change on this code

– flopcoder
Nov 23 '18 at 9:46















change this to String allAlphabate = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; and then remove tolowercase function in sevaral places

– flopcoder
Nov 23 '18 at 9:48





change this to String allAlphabate = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; and then remove tolowercase function in sevaral places

– flopcoder
Nov 23 '18 at 9:48













0














try this:



String str = new PDFTextStripper().getText(doc);    
int len = str.length();
Map<Character, Integer> numOfChars = new HashMap<Character, Integer>(Math.min(len, 26));

for (int i = 0; i < len; ++i)//pre increment
{
char alphabet = str.charAt(i);
if (!numOfChars.containsKey(alphabet ))
{
numOfChars.put(alphabet , 1);
}
else
{
numOfChars.put(alphabet , numOfChars.get(alphabet ) + 1);
}
}
System.out.println(numOfChars);


Source






share|improve this answer
























  • these code basically print not only alphabet, it print symbol also like "=9, !=2

    – Choy
    Nov 23 '18 at 9:26











  • @Choy it is giving output like this {a=3, s=1, d=1, w=1, h=1, i=2, m=1, n=4} what else do you want?

    – nimi0112
    Nov 23 '18 at 10:12













  • no the output contain others else

    – Choy
    Nov 23 '18 at 10:31
















0














try this:



String str = new PDFTextStripper().getText(doc);    
int len = str.length();
Map<Character, Integer> numOfChars = new HashMap<Character, Integer>(Math.min(len, 26));

for (int i = 0; i < len; ++i)//pre increment
{
char alphabet = str.charAt(i);
if (!numOfChars.containsKey(alphabet ))
{
numOfChars.put(alphabet , 1);
}
else
{
numOfChars.put(alphabet , numOfChars.get(alphabet ) + 1);
}
}
System.out.println(numOfChars);


Source






share|improve this answer
























  • these code basically print not only alphabet, it print symbol also like "=9, !=2

    – Choy
    Nov 23 '18 at 9:26











  • @Choy it is giving output like this {a=3, s=1, d=1, w=1, h=1, i=2, m=1, n=4} what else do you want?

    – nimi0112
    Nov 23 '18 at 10:12













  • no the output contain others else

    – Choy
    Nov 23 '18 at 10:31














0












0








0







try this:



String str = new PDFTextStripper().getText(doc);    
int len = str.length();
Map<Character, Integer> numOfChars = new HashMap<Character, Integer>(Math.min(len, 26));

for (int i = 0; i < len; ++i)//pre increment
{
char alphabet = str.charAt(i);
if (!numOfChars.containsKey(alphabet ))
{
numOfChars.put(alphabet , 1);
}
else
{
numOfChars.put(alphabet , numOfChars.get(alphabet ) + 1);
}
}
System.out.println(numOfChars);


Source






share|improve this answer













try this:



String str = new PDFTextStripper().getText(doc);    
int len = str.length();
Map<Character, Integer> numOfChars = new HashMap<Character, Integer>(Math.min(len, 26));

for (int i = 0; i < len; ++i)//pre increment
{
char alphabet = str.charAt(i);
if (!numOfChars.containsKey(alphabet ))
{
numOfChars.put(alphabet , 1);
}
else
{
numOfChars.put(alphabet , numOfChars.get(alphabet ) + 1);
}
}
System.out.println(numOfChars);


Source







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 7:49









nimi0112nimi0112

8961722




8961722













  • these code basically print not only alphabet, it print symbol also like "=9, !=2

    – Choy
    Nov 23 '18 at 9:26











  • @Choy it is giving output like this {a=3, s=1, d=1, w=1, h=1, i=2, m=1, n=4} what else do you want?

    – nimi0112
    Nov 23 '18 at 10:12













  • no the output contain others else

    – Choy
    Nov 23 '18 at 10:31



















  • these code basically print not only alphabet, it print symbol also like "=9, !=2

    – Choy
    Nov 23 '18 at 9:26











  • @Choy it is giving output like this {a=3, s=1, d=1, w=1, h=1, i=2, m=1, n=4} what else do you want?

    – nimi0112
    Nov 23 '18 at 10:12













  • no the output contain others else

    – Choy
    Nov 23 '18 at 10:31

















these code basically print not only alphabet, it print symbol also like "=9, !=2

– Choy
Nov 23 '18 at 9:26





these code basically print not only alphabet, it print symbol also like "=9, !=2

– Choy
Nov 23 '18 at 9:26













@Choy it is giving output like this {a=3, s=1, d=1, w=1, h=1, i=2, m=1, n=4} what else do you want?

– nimi0112
Nov 23 '18 at 10:12







@Choy it is giving output like this {a=3, s=1, d=1, w=1, h=1, i=2, m=1, n=4} what else do you want?

– nimi0112
Nov 23 '18 at 10:12















no the output contain others else

– Choy
Nov 23 '18 at 10:31





no the output contain others else

– Choy
Nov 23 '18 at 10:31


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442215%2fhow-to-count-the-number-of-alphabet-in-a-pdf-file-in-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga