9 Replies - 8979 Views - Last Post: 26 April 2010 - 06:02 AM Rate Topic: -----

#1 vi0rulez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-February 07

.contentEquals method

Posted 21 February 2007 - 11:43 AM

can anyone please tell me y the .contentequals method which i use after getting the user's input from the console doesnt work?

import java.io.*;
import java.util.*;
public class TestHarness {

	public static String readLine(){
	StringBuffer response = new StringBuffer();
	try {
		BufferedInputStream buff = new BufferedInputStream(System.in);
		int in=0;
		char inChar;
		do {
			in= buff.read();
			inChar = (char) in;
			if (in!=-1){
				response.append(inChar);
			}
		}while ((in != -1) & (inChar != '\n'));
		buff.close();
		return response.toString();
	} catch (IOException e) {
		System.out.println ("Exception:" + e.getMessage());
		return null;
	}
String go = "go";
String input = ConsoleInput.readLine();
	[b]if (input.contentEquals(go))[/b] { 


Is This A Good Question/Topic? 0
  • +

Replies To: .contentEquals method

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: .contentEquals method

Posted 21 February 2007 - 11:57 AM

I think that the
input.contentEquals(go)
should be
input.equals(go);
Was This Post Helpful? 0
  • +
  • -

#3 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: .contentEquals method

Posted 21 February 2007 - 12:02 PM

I'm going to give you a big hint. I could just tell you, but learning to read the API is a something that is really important. Here is the API JavaDoc for the String class: http://java.sun.com/...ang/String.html

Look at the method signatures for contentEquals and then look at your method call and see if you can figure out why it's not working.

View PostPennyBoki, on 21 Feb, 2007 - 12:57 PM, said:

I think that the
input.contentEquals(go)
should be
input.equals(go);

OK, you beat me to the "Add Reply" button. :)
Was This Post Helpful? 0
  • +
  • -

#4 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: .contentEquals method

Posted 21 February 2007 - 12:10 PM

It was the FASTREPLY button actually :)
Was This Post Helpful? 0
  • +
  • -

#5 vi0rulez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-February 07

Re: .contentEquals method

Posted 21 February 2007 - 12:39 PM

i've tried that but still doesnt work..
if i dont declare a string variable isnt there a way with the contenteqals method to just compare the text?

This post has been edited by vi0rulez: 21 February 2007 - 12:51 PM

Was This Post Helpful? 0
  • +
  • -

#6 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: .contentEquals method

Posted 21 February 2007 - 02:27 PM

View Postvi0rulez, on 21 Feb, 2007 - 01:39 PM, said:

i've tried that but still doesnt work..
if i dont declare a string variable isnt there a way with the contenteqals method to just compare the text?


Are you sure the contentEquals method takes a String? Check the Javadoc just to be sure.
Was This Post Helpful? 0
  • +
  • -

#7 vi0rulez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-February 07

Re: .contentEquals method

Posted 21 February 2007 - 02:43 PM

yes it does..
Was This Post Helpful? 0
  • +
  • -

#8 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: .contentEquals method

Posted 21 February 2007 - 04:33 PM

Really? Because I'm looking at the API and I only see two methods by that name, none of which have a String as the parameter:

public boolean contentEquals(CharSequence cs)
public boolean contentEquals(StringBuffer sb)

Was This Post Helpful? 0
  • +
  • -

#9 Guest_Max*


Reputation:

Re: .contentEquals method

Posted 26 April 2010 - 01:06 AM

@Programmist I know this thread is ancient and you've probably learned this but I'll say it anyway. contentEquals DOES accept String as an argument because String implements CharSequence.
Was This Post Helpful? 1

#10 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10573
  • View blog
  • Posts: 39,148
  • Joined: 27-December 08

Re: .contentEquals method

Posted 26 April 2010 - 06:02 AM

Good show. :^: Completely worth the necropost.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1