StringTokenizer 1 « StringTokenizer « Java Data Type Q&A





1. StringTokenizer - first string?    stackoverflow.com

I have this code to parse url string such as "?var=val" but when "search" is just "var=val" this code fails, how to make just "var=val" work as well?

    StringTokenizer ...

2. how to use java stringtokenizer?    stackoverflow.com

how to use java stringtokenizer for the below string |feild1|field2||field4|... i want java to take the blank as a field too, but stringtokenizer is skipping it. Any option to get it?.

3. String Tokenizer    stackoverflow.com

Can anybody help me understand how this string tokenizer works by adding some comments into the code? I would very much appreciate any help thanks!

public String[] split(String toSplit, char delim, boolean ...

4. Java StringTokenizer troubles - Newbie    stackoverflow.com

I know I'm probably being incredibly stupid here, but can anybody shed any light on my problem? I'm trying to extract the title from a string containing html...

 public static void ...

5. Java: string tokenizer and assign to 2 variables?    stackoverflow.com

Let's say I have a time hh:mm (eg. 11:22) and I want to use a string tokenizer to split. However, after it's split I am able to get for example: 11 ...

6. stringtoList issue    stackoverflow.com

I have a stringtoList ArrayList that needs to return tokens from a StreamTokenizer but the s.sval is not compiling at run-time, can anyone help me with this problem:

private List<Token> stringToList(final String ...

7. String tokenizer, sanitize input?    stackoverflow.com

I'm working on a program that takes in book records in the form

<book #>,<name>,<publisher>
for example
123,Example Book,Publisher
After which, the user is returned to a menu, using numbers to select what option they ...

8. Infinite Loop in Java    stackoverflow.com

So I'm trying to look at an input, and count words that fit a certain criteria (or rather, excluding words that I don't want to count). The error is in the ...

9. Parsing a string-what should be the end-index for the newline?    stackoverflow.com

Your request for ...

Good morning Mr Praneel PIDIKITI
you have succ.....
This is my string i want to parse this string in order to get the value Praneel PIDIKITI i am using
 ...





10. stringtokenizer and an unknown variable type    stackoverflow.com

I’m currently working on a project in which I stream in a text document and tokenize it. The only problem is the types in the text document is unknown, is there ...

11. String Tokenizer Simple Calculator - Java    stackoverflow.com

I need to use StringTokenizer, which I have, but something is wrong. I'm having some trouble finding out where. Here is my code so far:

import java.util.*; 

public class Calculator
{ 
  ...

12. String Tokenizer issue    stackoverflow.com

AM using string tokenizer to delimit the string response by ^

12/30/2011 12:00:00 AM^President^^^159^True^True^True^True^True^False^False^True^True^3/18/2011 12:00:00 AM^True^Jujama, Inc.^^^^True^True
but the problem is when ^ delimiter consecutively its skipping that one and adding in to ...

13. StringTokenizer method equivalence    stackoverflow.com

Why do hasMoreElements and hasMoreTokens return the same value?

14. String Tokenizer in Java    stackoverflow.com

I am using String Tokenizer in my program to separate strings. Delimiter I am trying to use is ");". But I found out that StringTokenizer uses ) and ; as 2 different ...

15. How to extract the proper String?    stackoverflow.com

I have a string like this:

 14.809180,56.876968,0.000000 14.808170,56.877048,0.000000 14.805100,56.877220,0.000000 14.804130,56.877338,0.000000
i.e, at the beginning there's a space and also after 0.000000 there's a space. I just want to extract 14.XYZ and ...

16. string tokenizer inservlets    coderanch.com





17. Alternative to StringTokenizer    coderanch.com

18. StringTokenizer and Loop Help    coderanch.com

19. StringTokenizer    coderanch.com

Hi, I've a query: . . . "HAVING leeftijd BETWEEN "+MinAge+" AND "+MaxAge+"+ . . . I've a String age. I get this String from a jsp as a parameter. String _age = request.getParameter("age"); The age String can be: "0 - 5", "6 - 12" or "13 - 18" where the 0,6 and 13 are the minAge, and 5, 12 or ...

20. StringTokenizer    coderanch.com

Hello All, I am trying to create an int[] from a string that I get from my getter (9,10,11,12,13,14,15,16). I've verified that the string is passed in the format above. However when I loop to through the Tokenizer it skips values in my string. Also my new Array values are all set to 0. This is my output. Would someone point ...

21. StringTokenizer    coderanch.com

I have a String; for example, Citizen Action: Salvation Army~6 The '~' is the delimiter. And I want to use the java.util.StringTokenizer to get two tokens: one is the 'Citizen Action: Salvation Army' and the other is the '6'. And then convert '6' back to an Int. I am calling a TokenUtil class to do the job TokenUtil.getTokens( stringToBeParsed ); Pass ...

22. String Tokenizer    coderanch.com

23. StringTokenizer    coderanch.com

Hello Friends How are you all... I have propblem in reading the message from the FTP Service i get the message like this ..Client will receive the Following Messages from service: message LocalFTP~Networkshare~ServiceVersion~ServiceRelease~ServiceControlVersion~ServiceControlRelease\r\n here "message" can be --> ACCEPTED, COMPLETED, PROGRESS, INVALID. ex: ACCEPTED D:\FTP~D:\Share~v1~R2.1.1.0~v1~R1.1.1.0 COMPLETED D:\FTP~D:\Share~v1~R2.1.1.0~v1~R1.1.1.0 PROGRESS D:\FTP~D:\Share~v1~R2.1.1.0~v1~R1.1.1.0 INVALID i have to tokenize this each one and write into the ...

24. StringTokenizer Blues    coderanch.com

Hi, I have a String in which there are 5 tokens taht are delimited by tabs ("\t"). I was using the StringTokenizer to parse this line and get individual tokens. It worked fine, till I encountered a situation where there were 2 tabs (instead of 1). Now, since StringTokenizer doesn't return me an empty string, how can I find out if ...

25. Nulls in StringTokenizer    coderanch.com

Hi , I have a tab separated file and I have to port the data to DB through StringTokenizer.Every thing is worrking fine, except whenever there is a "null", String Tokenizer simply ignores it. For example, If my string is : - TERMINOLOGYGOOGLE ( signifies tab) then I will get two tokens as TERMINOLOGY and GOOGLE. But if I have TERMINOLOGYGOOGLE ...

26. StringTokenizer Bug?    coderanch.com

Ok simple short and sweet. I'm writting an application that used the StringTokenizer to parse thru data. I am delimiting it by comma (,). Example Data: "a,b,c,,e" When I iterate thru the String I would expect the StringTokenizer to process this result: "a" "b" "c" "" "e" Instead I'm getting: "a" "b" "c" "e" Any idea why the StringTokenizer isn't tokenizing ...

27. StringTokenizer    coderanch.com

Hi, I have been trying to get this simple function to work as it is stated in the reference library. Instead of changing from true to false after going through the characters and breaking the loop, it keeps resolving as true indefinately. It doesn't break out of the while loop. Have no idea what I am doing wrong. int linecount = ...

28. StringTokenizer    coderanch.com

29. StringTokenizer in Jdk1.5    coderanch.com

30. Doubt about StringTokenizer !!    coderanch.com

Hello Everybody. I am using StringTokenizer to read a CSV(uploaded) file and write it into a file..... My problem is, i want to allow user to upload a CSV file which has got only 19 colunms in it. Not less than or more than 19 columns. I don't how how to do that. I am pasting code here try { String ...

31. StringTokenizer / NullPointerException problem    coderanch.com

I have been getting a NullPointerException during this specific section in my application. I assume that the StringTokenizer is grabbing a null value which is causing the problem, but it is my understanding that the hasMoreTokens() method should eliminate that problem. The input file that I use is a .csv file. public String ipScrub(String replacement) { String scrubbed = null; try ...

32. String Tokenizer    coderanch.com

thanks alot for yr suggestion. i will look into it. i just want to ask something. in order for me to store the data from the text file, after i have the String Tokenizer to retrieve all the data, i was thinking that i should have a nested loop and array to temporarily store it before i actually save it inside ...

33. StringTokenizer with hasNext method as condition    coderanch.com

This is my code using File Reader and BufferedReader. I have a minor problem whereby i want to perform a method to check whether is there any additional data in every line in the text file. if yes, it will continue to display, if not, it will then stop. i know i could use hasNext but i couldn't get the condition ...

34. If StringTokenizer is no longer recommended, then what?    coderanch.com

I am writing a program to parse a homegrown kind of pseudo-code, where the delimiters are almost never white space (except newlines) and they change as you go along, depending on what has been read so far. E.g. text enclosed in curly braces is treated specially, and in fact you might have nested curly-brace-enclosed phrases. So when I start processing a ...

35. StringTokenizer    coderanch.com

i save this whole this as a string..... Senior Project Manager-1,Assistant Manager-1,Chainmen-2,Clerk Of Work-1 Asistant Manager-1,Chainmen-2,Clerk Of Work-1 How do i know that this record is end of line..... for example i have this 2 data......i using StringTokenizer to separate it and how do i want to get one by one.......because every line of data it have different total of the ...

36. Doubts in the operation of StringTokenizer    coderanch.com

Hi All, Please look at the following code: import java.util.*; public class Tester { public static void main(String[] args) { StringTokenizer st = new StringTokenizer("CustomeCare.$ser$",".$ser$"); while(st.hasMoreTokens()){ System.out.println(st.nextToken()); } } } I am getting the output as: Cu tom Ca Does the "$"symbol has anything to do with the operation of tokenizing the String? Please explain. Thanks in Advance!!! dinesh.

37. StringTokenizer    coderanch.com

Originally posted by jite eghagha: Any one understand why my token returns an entire line? it totally ignores the "\t" delimeter i set. My file i'm reading for is tad demlimeted in Excel. String line = buff.readLine(); for(int y = 0; y < getMaxV(); y++) StringTokenizer tok = new StringTokenizer(line, "\t"); string = tok.nextToken();

38. StringTokenizer length    coderanch.com

Hi I am writing data into .dat file. I set a const column length (for example 20 char). For each token I need to check the length and to add the remainder length so the next token will be written after 20 char and the next one will be written 40 char etc. StringTokenizer stringTokenizer = new StringTokenizer("this is a test"); ...

39. StringTokenizer    coderanch.com

Hi, I am reading lines from a txt file and splitting words using StringTokenizer. My code is as below: File: Line 1 aaa bbb ccc ddd Line 2 rrr ttt uuu BufferedReader in = new BufferedReader(new FileReader(FILENAME)); String line = in.readLine(); while(line != null) { StringTokenizer tk = new StringTokenizer(line); String first = tk.nextToken(), second = tk.nextToken(), third = tk.nextToken(), fourth ...

40. Regarding string tokenizer    coderanch.com

Hi Ranchers, I have a written a method to return me the token of a string by specifing the token as argument in the method. for example when 2 is passed as an argument it returns me the second token. When the method is passed as 0 or more than the number of tokens I am returning null. Can you please ...

41. Use StringTokenizer    coderanch.com

42. what is StringTokenizer ?    coderanch.com

43. StringTokenizer and the "" empty string    coderanch.com

Hello, My strings look like this: "001668","RTOFENTRY","LICENSE","","SJC","","00000431","Rental Car" Notice the "" empty string. My StringTokenizer's constructor takes care of delimiter characters StringTokenizer token = new StringTokenizer(str, ",\""); The problem is that the "" empty string is not counted as a token! So instead of my token count to be 8, i get a 6. How would you deal with this. Any ...

44. StringTokenizer    coderanch.com

I am working on a school project on building a simple compiler. I have the I/O pretty much worked out as to reading in the file and then printing it back out to the screen and another file etc. Okay, now where I am running into a bit of a problem is Taking these tokens that I am reading in and ...

45. using string tokenizer to retrieve rationals    coderanch.com

The example code for my assignment follows. We are to use rationals instead of integers. My partner and I have tried this program several ways, but have not been able to get the tokenizer to extract the numerator/denominator. Could any of you help out please? Also, for those of you who prompted me to solve the "extend" problem I posted, my ...

46. String Tokenizer    coderanch.com

Hi I Since everything is a string in your example.. use "," as the 'token'.. BUT, you will have to use indexOf to get a position of each token and then subString() the token out of the String. This is because the StringTokenizer will consider the "," as a list of tokens to check for. Ex: "Hi","there","me,you" Would give you 3 ...

47. StringTokenizer    coderanch.com

Thanx a lot... I had found out the solution in the following two ways: Method1: final String strDelimiter = "~"; StringTokenizer strTokObj = new StringTokenizer( strData, strDelimiter, true ); String strPrevToken = ""; String strCurrToken = ""; while( strTokObj.hasMoreTokens() ) { strCurrToken = strTokObj.nextToken(); if( strCurrToken.equals( strDelimiter ) ) { if( strCurrToken.equals( strPrevToken ) ) { strCurrToken = ""; } } ...

48. String tokenizer    coderanch.com

import java.util.StringTokenizer; public class TokenTest { public static void main(String args[]) { String temp = "1003$$03$$$$suggestion1"; String delim = "$a";//see this String token = null; StringTokenizer st = new StringTokenizer(temp,delim,true); int i=0; while (st.hasMoreElements()) { System.out.println(""+(i+1)+"["+st.nextToken()+"]"); i++; } System.out.println("\n"); st = new StringTokenizer(temp,delim); i=0; while (st.hasMoreElements()) { System.out.println(""+(i+1)+"["+st.nextToken()+"]"); i++; } } } output ------ C:\jdk\bin\java.exe TokenTest Working Directory - D:\ksoni\javaTests\ Class ...

49. StringTokenizer - perhaps    coderanch.com

You could try reading up on compiler theory. Basically you are implementing a parser and semantic routines, and using the StringTokenizer to fetch your tokens. There's bazillions of reasearch papers on the topic. But you basically need a mini-grammar to define legal operations, then your parser can assemble the tokens, and then you just need some orderly way of invoking semantic ...

50. String Tokenizer    coderanch.com

Hi sreeni. I have tried to solve ur problem.You can have other logic for this also.What i have done in this function is that i have used a temproryTokenizer.From this temproryTokeniser i have eliminated the tokens with values" " and null Then i have made the finalToknizer private void addTokens(String tokenString) { StringTokenizer tempTokeniser = new StringTokenizer(tokenString,","); String modifiedString =null; //counterToChekFirstToken ...

51. problem with StringTokenizer    coderanch.com

Hi tyler, I implemented suggestion of Dirk and this code works as you expected. import java.util.StringTokenizer; public class Ex7 { public static void main(String args[]){ StringTokenizer bgColor = new StringTokenizer("2,,",",",true); String strVal = null; boolean bCommaExpected = false; int[] background = {0,0,0}; for ( int i = 0,j=0; i < 5; i++ ) { while(bgColor.hasMoreTokens()){ strVal = bgColor.nextToken(); if((strVal.equals(","))&&(bCommaExpected == true)){ ...

52. String Tokenizer    coderanch.com

I can't seem to get the trim() to work. Here is my entire exercise. I may be heading in the wrong direction. Given a string(a text entered as a long string) entered by a user from the command line. 1. Write a program that eliminates leading spaces, trailing spaces, as well as extra spaces between words. (we assume one space seperates ...

53. StringTokenizer    coderanch.com

import java.util.regex.Pattern ; public class Foo { public static void main( String[] args ) { String input = "some stringAnother stringLast string" ; Pattern pattern = Pattern.compile( "" ); String[] splits = pattern.split( input ); for ( int i = 0 , length = splits.length ; i < length ; i++ ) { System.out.println( splits[ i ] ); } } } ...

54. StringTokenizer Class not Found    coderanch.com

56. String Tokenizer Crypting.    coderanch.com

57. StringTokenizer    coderanch.com

Help!! I've been out this program for awhile and can not get it to not count tab. For example, if I imput 'k k k', with tabs between each k, it will count it as a one 3 letter word, instead of three 1 letter words. Space works correctly, but tab does not. I know tab is one of the default ...

58. StringTokenizer    coderanch.com

59. StringTokenizer Issues    coderanch.com

Hi, I want to take a string such as "Hello" and convert that to a string that looks like this: "h + e + l + l + o" . This is the loop that I am using to try to accomplish this feat: import javax.swing.*; import java.text.*; import java.util.StringTokenizer; public class romanNumeral //Naming the class and declaring it to be ...

60. StringTokenizer    coderanch.com

Okay, I did make that change to length-1 and re-compiled the program, and I was given the following errors. C:\Documents and Settings\Kels\kelsey>javac TokenTest.java TokenTest.java:1: 'class' or 'interface' expected > import javax.swing.*; ^ TokenTest.java:2: 'class' or 'interface' expected > import java.util.*; ^ TokenTest.java:3: 'class' or 'interface' expected > import java.awt.event.*; ^ TokenTest.java:4: 'class' or 'interface' expected > import java.awt.*; ^ TokenTest.java:5: 'class' ...

61. simple stringTokenizer problem    coderanch.com

Hi mike, Thanks. Actually i tried \\w and it works too. Just when I thought its looking great..i have a new problem..as we are using jdk131 for the app server..it gave me a No such method error. So I realized the method replaceAll with support to regex is only in jdk141..As such I cannot use this method. We cannot change our ...

62. StringTokenizer confusion    coderanch.com

Hi, It seems to me that this problem is a little more difficult than it might first appear. Two issues: (1) You want to "keep" the thing you're splitting with - you want to split at + or -, but the + or - is significant and is kept as part of the string to its right. (2) The language you're ...

63. string tokenizer prob    coderanch.com

You could do a couple of things... but first... do you really need to store them now, and use them later? could you use the tokenizer later, to get them as needed? (i really don't know - it depends on your specific needs. but it's something to think about). assuming you really do need to pick them off now and store ...

64. String Tokenizer    coderanch.com

65. StringTokenizer    coderanch.com

66. String Tokenizer help    coderanch.com

i have a program that is using string tokenizer to grab a char and a double value, but the file's data is stored like this c 500 c 21000 p 550 c 5950 c 3000 <------------------------- l 4000 p 4050 and so on........... where i have that arrow is where i need help how would i get string tokenizer to skip ...

67. StringTokenizer Issue    coderanch.com

Hi Barry, Even split() doesn't give me an empty string"" or a null if there are two tabs in succession. What I want is, that if there are 2 consecutive tabs, then it should be able to detect that and give me an empty String or null which occurs between the two consecutive tabs.

68. StringTokenizer Class    coderanch.com

Im using a string tokenizer in my current class project, because I'm required too. heres the error message I am getting when I try and test the StringTokenizer, exception in thread "main" java.lang.NullPointersException at java.util.StringTokenizer. at java.util.StringTokenizer. at NewTextTrial. at NewTextTrial.main I have no idea what any of this means, but here is my actual code so that maybe ...

69. Question About String Tokenizer    coderanch.com

Hello there, I am having difficulty using the String tokenizer and the String buffer class together. Let me be specific, I am trying to search a String, if it has the word "and", I want everything on the right side of "and" to be one String, and the other side to be a totally different string. I thought about using an ...

71. StringTokenizer probelm    coderanch.com

72. StringTokenizer problem!    coderanch.com

Hi all, I am facing a dilemma regarding my StringTokenizer. I have this line as input : treasureisland adventure The movie is based blabla. More blabla the end. I declare a default stringtokenizer for this string.(delimiter = spaces) By reading the first 2 tokens, i read the moviename and the movie type. Is there a way to grab whats left of ...

73. StringTokenizer    coderanch.com

74. Question on StringTokenizer    coderanch.com

Originally posted by Adam Richards: Please help spread the word: The word "doubt" is inappropriate and confusing for subject lines. I have no idea what you mean by "doubt." Did you mean "confusion"? Even "confusion," though, is too vague. The more meaningful & specific your subject, the more meaningful & specific the replies will be.

75. StringTokenizer question    coderanch.com

Ok, you are right. Still it is discouraged from use. split is far cleaner. There is no reason to use it anyway. "StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead."

76. need help using StringTokenizer    coderanch.com

Hello, I need help writing code that converts a given name like into initials and surname. For example, if a name is Ricky James, it should do R James and if the name is Henry William James, that should become H W James. I have written a method that converts Ricky James to R James and I have used StringTokenizer, but ...

77. StringTokenizer    coderanch.com

78. StringTokenizer    coderanch.com

79. StringTokenizer Question?    coderanch.com

80. Stringtokenizer    coderanch.com

81. Stringtokenizer    coderanch.com

82. String Tokenizer Question    coderanch.com

Don't compare strings with ==, use equals() method. That's the main bug in your program. Or you might consider equalsIgnoreCase(), if you really want "b" to match "B". Another bug is that you call nextToken() twice in a row, without checking hasMoreTokens() in between. If a line has only one token, you'll get an exception there, which I suspect is not ...

83. StringTokenizer question    coderanch.com

First, I know a String is an Object. While all Strings are Objects. All Objects are not Strings. Second, I don't see how the return value could be a String upcast to an Object when a simple conditional test with the instanceof operator demonstrates that the returned value is actually String. The point of my question is that there seems to ...

84. Did you see this ?StringTokenizer    coderanch.com

When the Enumeration interface and StringTokenizer class were first written (in Java 1.0), Java did not have generics and overridden methods were not allowed to declare a return type that was a subclass of the overridden method's return type. Because Enumeration interface was used in more places then (Iterator did not exist), it's nextElement method was declared to return an Object ...

85. I always wonder about StringTokenizer ?    coderanch.com

87. Problem in StringTokenizer    coderanch.com

Am trying to split the String as (^) Separeted. Even I tryed Split method also..Any Other Way to split this one.. Please assist Me public static void main(String[] args) { String messStr = "A(^)B|#|TE^ST|#|BCF^ll(^)"; StringTokenizer st = new StringTokenizer(messStr, "(^)"); while(st.hasMoreTokens()) System.out.println(st.nextToken()); } OutPut ------ A B|#|TE ST|#|BCF ll Expected Ouput -------------- A B|#|TE^ST|#|BCF^ll I seen the String Tokenizer class they ...

88. String Tokenizer Problem    coderanch.com

Hi, I have a method which returns a String array of elements, i am going to display in a JList. I use a JSplitPane, the Left Side contains a JTree put in a JScrollPane, the Right Side contains the list of elements from the String array. How to count the elements using the StringTokenizer? I count the elements from the String ...

89. writing a class(List) similar to that of StringTokenizer    coderanch.com

I want to write a class in which a list which contains group of values say 15. i want to split according to the limit(given at the run time,for example if you give 5 as limit the result should be like this [ [0,1,2,3,4] , [5,6,7,8,9] , [10,11,12,13,14] ]. ) for this code i have done almost all the method such ...

91. NullPointerException at StringTokenizer    coderanch.com

Dear friends, The following code gives me a problem. import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.StringTokenizer; public class GeneratePCM { public static void main(String... args) { if(args.length == 0) { System.out.println("Enter full paths of input file name and ouput directory. Program will exit"); System.exit(0); } else if(args.length == 2) { BufferedReader inputBr ...

92. Stringtokenizer values.    coderanch.com

Hello. I have been lurking around here getting tips and advice for quite some time: it's greatly appreciated. I am, however, stumped, and need some help using Stringtokenizer. I will comment parts of code to keep it confidential, but what is posted should explain: import java.util.StringTokenizer; import java.util.*; public class getSongs { public static void main(String[] args) { try { //There ...

93. StringTokenizer    coderanch.com

94. Why StringTokenizer Discouraged nowadays ?    coderanch.com

More reasons: 1) What if your requirement changes from comma to comma with optional whitespace? It's much easier to change the code using split. 2) split is an idiom that reads more naturally 3) It's harder to misuse split. I've seen a delimiter of ", ". Upon first read, many people think this means matching a comma followed by a space. ...

95. StringTokenizer    coderanch.com

96. StringTokenizer / Speed    coderanch.com

Hi all, I hope I don't cause too much trouble with this one, but here goes: I am reading in a large collection of files (let us say ASCII .txt files for the sake of this example.) For my i/o, I am using JNI to do buffered reading in C land and get back a collection of Strings representing the lines ...

97. Need help with StringTokenizer    coderanch.com

I've two string which are delimited by ; list1="abc;cd;ef;xyz" list2="asd;ght;ef;xyz" Now I've to create list3 which will have tokens as a result of list1-list2 list3 will be "abc;cd" Please check out my code import java.io.*; import java.io.File; import java.util.*; public class strtkn { public static void main(String args[]) { String list1="abc;cd;ef;xyz"; String list2="asd;ght;ef;xyz"; String list3=""; StringTokenizer st = new StringTokenizer(list1, ";"); ...

98. StringTokenizer does not work properly.    coderanch.com

99. Problem using StringTokenizer    coderanch.com

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; } } } }

100. Using StringTokenizer?    coderanch.com

Hey guys I have been programming a project, to count the number of words in a given text file. I am using the StringTokenizer with specified delimiters. The problem I am running into is that my count is displaying zero. I am not sure where my error lies. If someone could point out the error, I would greatly appreciate it. Thank ...