Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Devaka Cooray
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Jeanne Boyarsky
Tim Cooke
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Mikalai Zaikin
Carey Brown
Bartenders:
Forum:
Java in General
Problem using StringTokenizer
Ankur Premi
Greenhorn
Posts: 17
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am trying to use StringTokenizer for saving the value of
val
(See code below) in different variables.
I have written this code. But this code is returning null values. It's not saving the value of
val
corresponding to the
key
.
import java.util.StringTokenizer; class add { static String in = "name=john;age=20;sex=male"; public static void main(String args[]) { StringTokenizer st = new StringTokenizer(in, "=;"); while(st.hasMoreTokens()) { String key = st.nextToken(); String val = st.nextToken(); if(key=="name"){ String s1=val; } if(key=="age"){ System.out.println(key + "\\t" + val); String s2=val; } if(key=="sex"){ System.out.println(key + "\\t" + val); String s3=val; } } } }
Please help me.
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I suppose, it wont even enter the three if statements. How did you decide it gives null values?
Use equals() to compare the contents of 2 strings.'==' is used to check reference equality.
OCPJP 6
Ankur Premi
Greenhorn
Posts: 17
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thank you vinoth. it worked
Campbell Ritchie
Marshal
Posts: 78660
374
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Ankur Premi wrote:
I am trying to use StringTokenizer . . .
Why? It is a legacy class.
Shiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
File Operations Program Problem
Tokenizing after reading from a file
How to search a Vector array?
exercise getServiceByName
please help with tokenizing
More...