This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes string management Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "string management" Watch "string management" New topic

string management

Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63
hi friends,

i have a problem on managing input strings on a program.

i have to make a program in which on hitting "enter" or a particular word the program should show some output.

the code of my program: -

import java.lang.*;
import java.util.*;

public class test

public static void main(String args[])
//ctrl-c to terminate the program
InputStreamReader keyreader = new InputStreamReader(;
BufferedReader bfreader = new BufferedReader(keyreader);
System.out.println("Enter the element: ");
String name = bfreader.readLine();
if (name == "test")
System.out.println("this is a test");
else if (name == "")
catch(Exception e)

here on giving the word test or simply hitting enter the program does not show the results as required.

any help

Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hi Pradyut,

You must use the equals() method to compare the String content.

[ November 15, 2004: Message edited by: Joyce Lee ]
GeeCON Prague 2014
subject: string management