Trying to have my method parse multiple words in a sentence but it only parses the first word.











up vote
-2
down vote

favorite












It seems my split isn't taking all words, only the first. How might I be able to make the split get all the words. I have looked up other answers to splitting strings but they don't seem to be working.



 public static int parseSentence(String input){
int startPoint = 0;
String badList = " .";
String words = input.split("\s+");
System.out.println(words[1]);
for(int x = 0; x < words.length;x++){
parseWord(words[x]);
}
return points;
}









share|improve this question






















  • can you check how many elements does the words have?
    – Kristjan Kica
    Nov 19 at 15:58






  • 2




    How do you know that only the first word is used? I hope not via System.out.println(words[1]); because that only prints one word and it would be the second. Besides that, your code look incomplete, e.g. points isn't defined and neither badList nor the result of parseWord is being used.
    – Thomas
    Nov 19 at 15:59












  • How might I do that?
    – Jake The Steak
    Nov 19 at 16:01






  • 1




    This means your input consists of a single word. Please report this input.
    – Robert Kock
    Nov 19 at 16:10






  • 1




    BTW, if words.length equals 1, you should get an Exception when printing words[1]
    – Robert Kock
    Nov 19 at 16:12















up vote
-2
down vote

favorite












It seems my split isn't taking all words, only the first. How might I be able to make the split get all the words. I have looked up other answers to splitting strings but they don't seem to be working.



 public static int parseSentence(String input){
int startPoint = 0;
String badList = " .";
String words = input.split("\s+");
System.out.println(words[1]);
for(int x = 0; x < words.length;x++){
parseWord(words[x]);
}
return points;
}









share|improve this question






















  • can you check how many elements does the words have?
    – Kristjan Kica
    Nov 19 at 15:58






  • 2




    How do you know that only the first word is used? I hope not via System.out.println(words[1]); because that only prints one word and it would be the second. Besides that, your code look incomplete, e.g. points isn't defined and neither badList nor the result of parseWord is being used.
    – Thomas
    Nov 19 at 15:59












  • How might I do that?
    – Jake The Steak
    Nov 19 at 16:01






  • 1




    This means your input consists of a single word. Please report this input.
    – Robert Kock
    Nov 19 at 16:10






  • 1




    BTW, if words.length equals 1, you should get an Exception when printing words[1]
    – Robert Kock
    Nov 19 at 16:12













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











It seems my split isn't taking all words, only the first. How might I be able to make the split get all the words. I have looked up other answers to splitting strings but they don't seem to be working.



 public static int parseSentence(String input){
int startPoint = 0;
String badList = " .";
String words = input.split("\s+");
System.out.println(words[1]);
for(int x = 0; x < words.length;x++){
parseWord(words[x]);
}
return points;
}









share|improve this question













It seems my split isn't taking all words, only the first. How might I be able to make the split get all the words. I have looked up other answers to splitting strings but they don't seem to be working.



 public static int parseSentence(String input){
int startPoint = 0;
String badList = " .";
String words = input.split("\s+");
System.out.println(words[1]);
for(int x = 0; x < words.length;x++){
parseWord(words[x]);
}
return points;
}






java arrays split






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 15:57









Jake The Steak

61




61












  • can you check how many elements does the words have?
    – Kristjan Kica
    Nov 19 at 15:58






  • 2




    How do you know that only the first word is used? I hope not via System.out.println(words[1]); because that only prints one word and it would be the second. Besides that, your code look incomplete, e.g. points isn't defined and neither badList nor the result of parseWord is being used.
    – Thomas
    Nov 19 at 15:59












  • How might I do that?
    – Jake The Steak
    Nov 19 at 16:01






  • 1




    This means your input consists of a single word. Please report this input.
    – Robert Kock
    Nov 19 at 16:10






  • 1




    BTW, if words.length equals 1, you should get an Exception when printing words[1]
    – Robert Kock
    Nov 19 at 16:12


















  • can you check how many elements does the words have?
    – Kristjan Kica
    Nov 19 at 15:58






  • 2




    How do you know that only the first word is used? I hope not via System.out.println(words[1]); because that only prints one word and it would be the second. Besides that, your code look incomplete, e.g. points isn't defined and neither badList nor the result of parseWord is being used.
    – Thomas
    Nov 19 at 15:59












  • How might I do that?
    – Jake The Steak
    Nov 19 at 16:01






  • 1




    This means your input consists of a single word. Please report this input.
    – Robert Kock
    Nov 19 at 16:10






  • 1




    BTW, if words.length equals 1, you should get an Exception when printing words[1]
    – Robert Kock
    Nov 19 at 16:12
















can you check how many elements does the words have?
– Kristjan Kica
Nov 19 at 15:58




can you check how many elements does the words have?
– Kristjan Kica
Nov 19 at 15:58




2




2




How do you know that only the first word is used? I hope not via System.out.println(words[1]); because that only prints one word and it would be the second. Besides that, your code look incomplete, e.g. points isn't defined and neither badList nor the result of parseWord is being used.
– Thomas
Nov 19 at 15:59






How do you know that only the first word is used? I hope not via System.out.println(words[1]); because that only prints one word and it would be the second. Besides that, your code look incomplete, e.g. points isn't defined and neither badList nor the result of parseWord is being used.
– Thomas
Nov 19 at 15:59














How might I do that?
– Jake The Steak
Nov 19 at 16:01




How might I do that?
– Jake The Steak
Nov 19 at 16:01




1




1




This means your input consists of a single word. Please report this input.
– Robert Kock
Nov 19 at 16:10




This means your input consists of a single word. Please report this input.
– Robert Kock
Nov 19 at 16:10




1




1




BTW, if words.length equals 1, you should get an Exception when printing words[1]
– Robert Kock
Nov 19 at 16:12




BTW, if words.length equals 1, you should get an Exception when printing words[1]
– Robert Kock
Nov 19 at 16:12

















active

oldest

votes











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',
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%2f53378380%2ftrying-to-have-my-method-parse-multiple-words-in-a-sentence-but-it-only-parses-t%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378380%2ftrying-to-have-my-method-parse-multiple-words-in-a-sentence-but-it-only-parses-t%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

Tonle Sap (See)

I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

Guatemaltekische Davis-Cup-Mannschaft