[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 21 KB, 533x400, 1315882700930.jpg [View same] [iqdb] [saucenao] [google]
5604318 No.5604318[DELETED]  [Reply] [Original]

I'm trying to code a method in Java that returns true or false, depending on if a supplied string matches any word in an array list, but I think there's a simpler way to do it, than I am. What I have is

public boolean isKnownWord(String word)
{
boolean trueOrFalse = false;
for(String testWord: words)
{
if(testWord.equalsIgnoreCase(word))
{
trueOrFalse = true;
}
}
return trueOrFalse;
}

Can anyone help?

>> No.5604333

>>>/g/
>>>/prog/
>>>/compsci101/
>>>/r.eddit/

I didn't think 5 year olds were allowed near a computer. Might spill their spaghetti hoops and milk on it.

>> No.5604354

Java makes me nauseous.

>> No.5604367

>>5604333
I figured all the ass bandits were too busy sucking cocks to have time to reply. No need to take out your homosexual frustrations on me, could've just told me that I had the wrong board.

>> No.5604382

public boolean isKnownWord(String n)
{
for(String h: words)
if(n.equalsIgnoreCase(h))
return true;
return false;
}

There are more efficient ways, though.

Also, Java sucks.

>> No.5604414

>>5604382
Yeah. I'm finding that it's a pain in the ass, but I have to take it before I can take any other COSC classes. Thank you, that worked perfectly.

>> No.5604493
File: 315 KB, 800x1100, 3.jpg [View same] [iqdb] [saucenao] [google]
5604493

>>5604318
>I'm trying to code a method in Java
Why the fuck would you EVER do that shit?

Code in a real language or get the fuck out

>> No.5604503

>>5604493
[insert programming language flamewar here]

>> No.5604515
File: 87 KB, 927x768, Java_Sucks_by_m_hed.jpg [View same] [iqdb] [saucenao] [google]
5604515

>>5604503
>flamewar

Some retard actually supports java? The fuck

>> No.5604526

>>5604515
Nope, I don't like it myself. But I'm sick of these endless discussions.

>> No.5604556

>>5604526
The unanimous consensus is that java is garbage and only exist because computer science majors are too retarded to understand real languages or *gasp* unsigned/complex numbers.

>> No.5604582

>>5604556
What the fuck does Java have to do with complex numbers?

>> No.5604589

>>5604318
run through your arraylist with a for loop, and just keep matching, if found return true else return false. Isn't hard, are you 10?

>> No.5604597

>>5604589
And now look what he did (in some lines of code more than necessary, true that).
What the fuck is wrong with you?

>> No.5604622

>>5604582
doesn't support complex data types, doesn't support unsigned data types, doesn't support pointers, doesn't support operator overloading, doesn't support goto, doesn't even support basic coding constructs like "if(x){...}"

>> No.5604620

>>5604597
Then use recursion.
public boolean foo (ArrayList a)
if a.length == 0
return false;
if (a.elementAt(0).equals(word))
return true;
return foo(rangeOf(1, length);

API for the method names

>> No.5604660

>>5604318
public boolean isKnownWord(String word) {
return (words.indexOf(word) != -1);
}

>> No.5604678

>>5604660
Oh, wait. That is case sensitive.

>> No.5604686

You guys are retarded. Use the right language for the problem you're trying to solve. Need cross platform support? Javas a fairly decent choice.

But by being "hurr durr java is bad cos i heard someone say it is slow so im not gonna use it" is only limiting your choices and making you a worse developer in the process.

Don't get me wrong, I'm not saying you should be using Java all the time. I haven't touched it over a year. But you should always keep an open mind and consider every option when trying to solve a problem.

>> No.5604703

>>5604556
Herrrr my brother makes > $150k programming java