Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners java declare two string values in single program
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Anitha
java declare two string values in single program
1 Answer(s)      2 years and 9 months ago
Posted in : Java Beginners


dear friends, If you declare two string values in single program like

class StringDemo { public static void main(String args[])

{ String s=new String("hello"); s=new String("world"); System.out.println(s); }}

I am getting output: "world".what is the reason why am not getting the string value "happy".please help me am new to java


Advertisement
View Answers

March 14, 2012 at 4:13 PM


String s=new String("hello"); when the above statement is executed a String object is created and s is pointing to that object.

s=new String("world"); Now a new String object is created whose value is "world" and s is now pointing to the new object whose value is "world" .

So,now no reference is pointing to "hello" object but the object is not removed. And when u say System.out.println(s), it indirectly mean as System.out.println(s.toString());



Related Tutorials/Questions & Answers:
Declare string array in Java (one and two dimensional)
Declare string array in Java (one and two dimensional... program also teaches you how to declare two dimensional array in Java... will learn how to declare string array in java. Java provides many ways to declare
How to declare String array in Java?
Following example will show you how to declare string array in java... elements of one dimensional array and two dimensional array. 1. String arr... ArrayDimensions { public static void main(String[] args) { //declare
Advertisements
write a program which asks the user for two int values and calculates their sum.
write a program which asks the user for two int values and calculates their sum.  The title says it all, an example is (1,2) > 3
Multiple values for a single parameter
Multiple values for a single parameter   ... multiples values for a single parameter like in checkboxes. We are going to make one... from where the values will be passed to the controller. In this program we have
String program - Java Beginners
String program  write a program to accept a word. Pass it to the function magic(String x). The function checks the string for the presence of consecutive letters. If two letters are consecutive in any position the function
java string vowel program
java string vowel program  java string vowel program   Please visit the following links: Display the word that begins with vowel Java Count Vowels
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem...","root","K13nn0r"); ResultSet rs=null; String SQL="select...=st.executeQuery(SQL); rs.last(); int k=rs.getInt(1)+1; String k2=rs.getString
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem...","root","K13nn0r"); ResultSet rs=null; String SQL="select...=st.executeQuery(SQL); rs.last(); int k=rs.getInt(1)+1; String k2=rs.getString
sorting an array of string with duplicate values - Java Beginners
string with duplicate values  How to check the string with duplicate values
how to store array values into two different tables in java?
how to store array values into two different tables in java?  I have... and now I want to store these values in two different tables(i.e store 2 array values in one table and remaining two values in another table
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
sorting an array of string with duplicate values - Java Beginners
String of Array  What is mean by string of array? And how one can add, delete the records from database in string format
sorting an array of string with duplicate values - Java Beginners
sorting an array of string  Example to sort array string
sorting an array of string with duplicate values - Java Beginners
sorting an array of string with duplicate values  I have a sort method which sorts an array of strings. But if there are duplicates in the array it would not sort properly
java program for string tokenzing and parsing
java program for string tokenzing and parsing  String s="height=128 weight=22 gender=male"; i need to convert this into height="128" weight="22" gender="male" normally if we print "hello" means we use System.out.println("\"Hello
java program for string tokenzing and parsing
java program for string tokenzing and parsing  String s="height=128 weight=22 gender=male"; i need to convert this into height="128" weight="22" gender="male" normally if we print "hello" means we use System.out.println("\"Hello
A Program To Reverse Words In String in Java
A Program To Reverse Words In String in Java  A Program To Reverse Words In String in Java for example: Input:- Computer Software Output... Tell Me This Program.  Here is an example that reverse the words
string program
string program  wap to find single occurrence of given string in java without using any predefined method
Reverse String Program in Java
Reverse String Program in Java We are going to describe about reverse string program in java. In this example reverses a string entered by the user. We... of the program: Enter a String Roseindia technology
Merge two list into a single list
Description: This example demonstrate how to merge two lists into a single... and the mergelist funtion merge the two lists into a single list. Code: # include... ( struct node *p ) { printf("The data values in the list are\n"
java program to compare two hashmaps and check whether they are equal or not
java program to compare two hashmaps and check whether they are equal or not  java program to compare two hashmaps and check whether they are equal
Swapping of two numbers
program to calculate swap of two numbers. Swapping is used where  you want to interchange the values. This program will help you to increase your programming ability. In this program we will see how we can swap two numbers. We can do
How to declare a Combobox without using a string in its declaration?
How to declare a Combobox without using a string in its declaration?  What i mean to ask is how can i declare a combobox first and initialise the values later? For example JComboBox x= new JComboBox(); ... String s={"Alpha
string program
string program  write a program to print the pattern p r o program r a m
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
Program using String functions - Java Beginners
Program using String functions  Write a program to accept a sentence... { public static void main(String[] args) { int count = 0...); System.out.print("Enter string:"); String st = input.nextLine
Advertisements
 

 

 

DMCA.com