Home arrow static arrow Java Programming [Archive] - compare three strings
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - compare three strings
This topic has 30 replies on 3 pages.    « Previous | 1 | 2 | 3 | Next »

Posts:24,036
Registered: 2/3/03
Re: compare three strings  
Aug 10, 2004 7:39 AM (reply 15 of 30)



 
...Second, even if it did,
you're only comparing the first element of the
array.

um... doesn't logic dictate that if [1] thru [n] equal
[0], any given index equals any other one?

Reply #14, and thanks for kicking me while I'm down.

 

Posts:11,186
Registered: 06.04.04
Re: compare three strings  
Aug 10, 2004 7:55 AM (reply 16 of 30)



 
...Second, even if it did,
you're only comparing the first element of the
array.

um... doesn't logic dictate that if [1] thru [n]
equal
[0], any given index equals any other one?

Reply #14, and thanks for kicking me while I'm down.


Oatmeal also causes severe counting disabilities :-P
 

Posts:24,036
Registered: 2/3/03
Re: compare three strings  
Aug 10, 2004 7:57 AM (reply 17 of 30)



 
...Second, even if it did,
you're only comparing the first element of the
array.

um... doesn't logic dictate that if [1] thru [n]
equal
[0], any given index equals any other one?

Reply #14, and thanks for kicking me while I'm down.


Oatmeal also causes severe counting disabilities :-P

Argh. #11. kick, kick
 

Posts:24,036
Registered: 2/3/03
Re: compare three strings  
Aug 10, 2004 7:58 AM (reply 18 of 30)



 
Where's that **** coffee?

Juan?!? Come hither! I need that 1,3,7-trimethylxanthine drip stat!
 

Posts:11,186
Registered: 06.04.04
Re: compare three strings  
Aug 10, 2004 8:09 AM (reply 19 of 30)



 
Where's that **** coffee?

Juan?!? Come hither! I need that 1,3,7-trimethylxanthine drip stat!

Caffeine acts as a diuretic and causes diarrhea and it raises the anxiety level as well. Especially
when combined with regular doses of oatmeal :-)

Jos
 

Posts:24,036
Registered: 2/3/03
Re: compare three strings  
Aug 10, 2004 8:14 AM (reply 20 of 30)



 
Where's that **** coffee?

Juan?!? Come hither! I need that
1,3,7-trimethylxanthine drip stat!

Caffeine acts as a diuretic and causes diarrhea and it
raises the anxiety level as well. Especially
when combined with regular doses of oatmeal :-)

Jos

Well, I guess I'm in deep sh....tuff.

BRB, I have to pee.
 

Posts:11,200
Registered: 7/22/99
Re: compare three strings  
Aug 10, 2004 8:19 AM (reply 21 of 30)



 
Where's that **** coffee?

Juan?!? Come hither! I need that
1,3,7-trimethylxanthine drip stat!

Caffeine acts as a diuretic and causes diarrhea and it
raises the anxiety level as well. Especially
when combined with regular doses of oatmeal :-)

Jos

Don't forget to mention its high level of [url http://www.dhmo.org]di-hydrogen monoxide[/url].
 

Posts:24,036
Registered: 2/3/03
Re: compare three strings  
Aug 10, 2004 8:20 AM (reply 22 of 30)



 
Where's that **** coffee?

Juan?!? Come hither! I need that
1,3,7-trimethylxanthine drip stat!

Caffeine acts as a diuretic and causes diarrhea and
it
raises the anxiety level as well. Especially
when combined with regular doses of oatmeal :-)

Jos

Don't forget to mention its high level of [url
http://www.dhmo.org]di-hydrogen monoxide[/url].

Dangerous substance, that...

 

Posts:4,496
Registered: 19/06/02
Re: compare three strings  
Aug 10, 2004 8:29 AM (reply 23 of 30)



 
"Borrowing" yawmarks idea ...
public static boolean allEqual(final String[] values) {  return (new HashSet(Arrays.asList(values)).size() == 1);}
 

Posts:11,186
Registered: 06.04.04
Re: compare three strings  
Aug 10, 2004 8:39 AM (reply 24 of 30)



 
Don't forget to mention its high level of [url=http://www.dhmo.org]di-hydrogen monoxide[/url].

That's the scientific name for oatmeal. yuck

Jos
 

Posts:1,135
Registered: 1/16/04
Re: compare three strings  
Aug 10, 2004 8:46 AM (reply 25 of 30)



 
Dangerous substance, that...

Apparently so...

Quote "Often associated with killer cyclones in the U.S. Midwest and elsewhere. "

- MaxxDmg...

- ' I am not me... '
 

Posts:2,830
Registered: 9/1/03
Re: compare three strings  
Aug 10, 2004 8:50 AM (reply 26 of 30)



 
"Borrowing" yawmarks idea ...

both ideas will perfom really badly (at least not optimally) if the
very first string is different, yet every other is equal. (or whatever).
	boolean areEqual(String[] b){		if(b == null || b.length < 2)			throw new IllegalArgumentException("why would you want to compare that?"); 		int max		= b.length;		String init	= b[0];		for(int k = 1; k < max; k++){			if(b[k] != init)				return false;		}		return true;	}
 

Posts:4,496
Registered: 19/06/02
Re: compare three strings  
Aug 10, 2004 9:02 AM (reply 27 of 30)



 
both ideas will perfom really badly (at least not
optimally) if the
very first string is different, yet every other is
equal. (or whatever).

But the code is "cool". That was the point of posting it.

btw: Your code is broken.
 

Posts:11,186
Registered: 06.04.04
Re: compare three strings  
Aug 10, 2004 9:03 AM (reply 28 of 30)



 
> if(b[k] != init)

Ahem.
 

Posts:2,830
Registered: 9/1/03
Re: compare three strings  
Aug 10, 2004 9:10 AM (reply 29 of 30)



 
> if(b[k] != init)

Ahem.

.. ****. i've been programming in c#, thats why :)
(c# allows the comparison of string-values this way.....)
 
This topic has 30 replies on 3 pages.    « Previous | 1 | 2 | 3 | Next »