String 15 « string « Java Data Type Q&A

1. Why doesnt writeChars(String) work the way its supposed to?

I am having trouble writing to a random access file using writeChars(string) function. The issue is that it puts way too many non-printable characters after each character. I could get it working with a BuffferedWriter but the requirement of the project we are working on is using random access file (academia). Is it possible to use Bufferedwriters with a random access ...

2. String class problem

i am beginer to java.i have one dout. That's not really a doubt, or even a dout. It's more of a question, or perhaps a "point of confusion". In java Every thing in the form of objects. That's not true. There are also primitives. Ruby or Python are languages where everything's an object. we must create a object to class,but for ...

3. String Tokenizing Question

What's your point? That both will work? They might, but String.split(",") is the cleanest solution. It doesn't require keeping track of whether it last saw a token or delimiter. Less code, and more natural of an expression. Do you just like to make things more complicated just to you can say you wrote more lines of code?

4. doubt on strings

But isn't strings a special case? Because of the constant string pool? As long as you dont create a new String with new String(); but only String = "...", won't both == and equals yield the same result? That's true. More specifically, all String literals are interned, but you can also intern other Strings. The golden rule is: always use equals. ...

5. Object obj = String.class;

6. Dividing string into specific parts

I have the scanner class search for the periods, but all that does is find the index of the periods for me. Is there a way to divide the domain name into three parts? If so, would I have to store them in three seperate variables and then used the reverse() function to switch them around?

7. string objects

8. String as identifier

Hey guys! I'd like to use a string to identify an object. for example, lets say my string s = "john", i want to create a robot named john. if s= "steve", i want the robot to be named steve. I've been scanning APIs and google and can't find anything except checking to see if a string is a valid identifier. ...

9. Java Strings

10. string

11. TypeCasting-float to String

12. Dropping Strings

for some reason, you are incorrect as to the fact that "inFile.readToken();" will return "street". Instead, it is returning something infront of "street", and thus the next token is "street, which you are trying to parse as an integer. for diagnostic purposes, try adding "inFile.readToken();" infront of "int b = inFile.readInt();". it shouldn't complain with the exact same error... but it ...

14. Question about to String method

I too, am really confused with your question. Are trying to overload a method so that it could return either a String or an int depending on the context? the toString method always returns a String, even if you do not override it. Your code is hard to follow because of your top secerete object, method, and variable names. JJ

15. How to send query string by using form action

Ur asking one question know why ur using javascript here. Because if I get any dynamic data in a sence it is easy to handling multiple data at a time. ok forget about come to the last line of the coding the "name " variable can have the two dynamically generated data ok.. if I get this data in the ...

16. how to make an if statemnt for an imported charecter or string...

import java.util.Scanner; public class ras { public static void main(String args[]) { int hrs=0; System.out.print("please input your customer type "); Scanner sc = new Scanner(; String customerType =; System.out.println("please input your usage hours per day "); hrs= sc.nextInt(); sc.close(); if(customerType =="b") System.out.println("recommended plan is business 200 "); //why is it not executing the instruction for the first if statement

17. Strings are mutable!

18. Question on String

19. Multiple strings?

20. clarification on strings

Diana12 wrote: Ecellent.....!!! Thanks a ton for the help. is this the same with string object's and how does intern() react with objects I don't understand your question. All Strings are objects. String s1 = "abc"; String s2 = new String("xyz"); This code has two String literals in it, abc" and "xyz". Therefore, when the class is loaded, two String objects ...

21. Scrolling String - Change in Speed

I'm confused. Why are you using threads when all you have is one thread controlling all 5 scrolling Strings? I thought your thread class would only control one String. Then in your main program create 5 threads each controlling one String. Doing it that way would certainly tidy up your code by getting rid of a lot of if statements.

22. To String

justinhol wrote: I am very new to java and am having a few problams. i have the code below. I also have more code for the enemy and food classes. However i am am having some problems with the toString method, i need the toString method to return the coordinates that get entered for the player"you" in the form you(x,y) etc. ...

23. Help with String

Your problem isn't leaping out at me. I'd suggest breaking that if() down and adding some print statements. Assign the previous and next characters to variables, not just the current one. Print them all before starting the first if. Print out where you are inside each if/else block. Also, for your middle else if, you will get an exception if the ...


streetfi8er wrote: thanks , the problem i am facing is that , i need to check for a large number of strings whether they satisfy the given condition , so do i need to have a regular expression for each string , or is there a way in which i can use the string as a regular expr? You can have ...

26. using strings in conditionals

27. Strings

28. Different ways to initialize a string

29. Need String program

30. Tokenizing a string with multiple delimiters

But I don't know for sure because I can't figure out what you are trying to say. The most confusing parts are you say "coordinates preceding the brackets" but yet there are no coordinates preceeding the first bracket. Also, there are 6 [ brackets and only 5 ] brackets, seems like there shouls be the same number of both, but maybe ...

31. Pull out part of string

32. String question

Hi, I came across a question in one of the exams and I was searching for answers, The answers available were : array, superclass, sublass and copy. I chose copy, but I dont know if it was right The question was : We create a _______ of a string object by passing the original string to the constructor Could you please ...

33. Strings issues

I need to write a simple code for something like this: Write a program that analyzes a string as follows: a. indicate if it ends with the three letters ing string compare = stringname.getChars(iend, 3); b. c. Print out the length of the string int count = stringname.length(); d. Print out the first character in the string string fdsdfs = stringname.getChars(istart, ...

34. An help with string and system.out

35. Why String is not included in the definition of Objects ?

Hi Guys, I was just glancing the JLS when I came across this definition of [Objects|] : An object (4.3.1) is a dynamically created instance of a class type or a dynamically created array. The values of a reference type are references to objects. All objects, including arrays, support the methods of class Object (4.3.2). String literals are represented by String ...

37. Clarification request for == on Strings

This is Java 101. You need to start here: [] == compares two references to see if they point to the exact same object. Since the new operator by definition creates a new Object, s1 and s2 necessarily must point to different objects. So == must return false. That's why you shouldn't use the new operator to create Strings unless you ...

38. object creation of string

Is the string pool is part of a heap? As i understand if i write String s = "hello"; the jvm will create a string literal "hello" in a string pool and s is referring to that literal. and if i write String s1 = new String ("hello"); the jvm will create a new string object in heap and s1 is ...

39. String method problems in a programm

I am trying to fix the compile errors in validCharacter and enoughDigits methods. If you remove these two methods it compiles and runs the menu fine. The errors are the following in enoughDigits method: unexpected type required: variable found : value if (Character.isDigit(symbol)= 2) What i am not understanding is how to change the value to a variable and count ...

40. Return an Attribute as an equivilent string?

41. String replacment

Hi I would like some help with replacing x amount of characters with another character efficiently. E.g. user inputs a string of characters, and each character is specified with a replacement which is converted to output. Problem is I have somewhat every possible character. E.g. Character ? = b ? = g ? = e So if I entered ??? my ...

42. small question about Strings

44. frequency string

45. Adding a string to another string

I feel a tad stupid asking this question, but I suppose that's what these forums are for, huh? I've not been doing java long (just started Comp' Science 5 weeks ago). I was playing about and made a string encrypter/decrypter the other day, which I then wanted to improve by having all the encryption/decryption code within a loop. However, I can't ...

46. String question

47. problem with strings

48. calling a String created in main method

49. String argument giving two different outputs ?

sure it does not works with String[] args, when the method is called the program pass "test" that isn't an array!!!! but I can't see the problem, classes have to write Alpha:foo,.... and the program made this! where is the problem???? maybe you want to write "test"? if you want to make this you have to write like: ... public void ...

50. String.toNumber()??

51. elements of a stack to a string

This sounds like a really bad idea to me. The whole point of a Stack is that you can only access one element at a time, the top element. To access the next element you need to remove the top element. Once you do that it is no longer part of the Stack and therefore should not be part of any ...

52. String Enquiry

Hi , i en-counted a problem recently with String while doing a project . String read read input from user using Scanner next().However the code below do not execute when user input 9 but if i change line 1 to if (read.charAt(0) == '9') the code execute perfectly . 1)Can any one explain what i did wrongly ? 2) is there ...

53. String Question

The reference of your StringBuffer object in main is passed by value to the method. What you have is a single SB object with 2 variables referencing it. So if you append anything inside the method it is being appended to the object that both variables reference. Then you create a completely new SB object that the local variable in the ...

54. Help getting a string

55. formatiing string

56. String object equivalency

Maybe someone could explain this to me. String a="abc"; String b="abc"; a == b // true I thought == compared the object reference, not the value. Is == overloaded in the String object or are Strings created differently than other objects so the two different variables really are pointing at the same object?

57. SortedSet< String > into a String[]

58. Or statement and String

59. Addition and subtraction within a string

If I have a string such as "5-8+111" What would be a reasonably simple way of computing the result of that. I have an array of these strings in a program and the porgram produces the above string... Other examples include: "10-5-8" There are never any spaces or other characters. Just integers and - or + ...

60. Creating a String

61. Properties to String with delimiter

62. Dividing a string.--- Urgent Help

Hi, I have a String like 0117A0100 .admin .01010000FRAZEE.CA810FA1.admin.2004030508342717836.1..0.0. M10000300 01000096..1000. I would like to split the string in to some fields like 0117 = RECORD-LEN---(Fixed Length) A = CHARSET-FLAG---(Fixed Length) 0100 = VERSION-NO---(Fixed Length) (sp) = ENCRYPT-FLAG---(Fixed Length) = ENCRYPT-DATA---(Variable Length) admin = TRADEMARK---(Variable Length) 0101 = DATA-PACKET-NO---(Fixed Length) 0000 = RESPONSE-NO---(Fixed Length) FRAZEE = CLIENT-ID---(Variable Length) CA810FA1 = ...

63. connection string

64. Problem with Strings

You told that... ""When you just use a String literal like String s = "abc", the String object already exists in the constant pool, and you're just getting a reference to that one, rather than to a newly created one."" can you tell me, How the String object is created which exists in the constant pool??

65. how to create a string with a slash in it.

66. Short wrapper , String

A short is a primitive: it's just a number, not an Object. See also: int, double, char, boolean A Short is an Object that contains a short. That's called a wrapper class, and it gives you functionality that you wouldn't find using primitives alone. See also: Integer, Double, Boolean A String is also an Object that represents some text. All of ...

67. Help with string object code

Hello, First off thanks in advance to anyone who helps. I am trying to write a program that using a class string object to convert this kind of "text speech" to english. For example if the user inputs "HowAreYou?", I want the program to output "How are you?" I am having too much trouble with strings for some reason. This is ...

68. String methods and utilities

Oh hai. I have a query. I'm doing an assignment which requires me to read in two strings, and compare the second to the first, finding how many times the second appears in the first. The thing that makes it tricky is that you can have punctuation in the first string such as ! , and '. Does anyone have any ...

70. Need a little help with strings

71. Help with strings

72. A method for defining the content of a String several times

private void comboBoxMinorChoosing1ActionPerformed(java.awt.event.ActionEvent evt) { if (blabla = true) { comboBoxMinorChoosing1.addItem("Math"); comboBoxMinorChoosing1String = comboBoxMinorChoosing1.getSelectedItem().toString(); }} public String comboBoxMinorChoosing1String { return comboBoxMinorChoosing1String; } String comboBoxMinorChoosing1String = ""; It all works as long as Im not trying to define the text twice, i know it isnt needed in the example I have given but in my actual application I do need to do ...

73. String Converion

74. inputting a string to the console

In the following code I am able to read in the first input ("title") as a sentence, but when I try to input another sentence ("publisher") a couple of inputs later, output console skips down to next line input ("price") before I can enter the "publisher". I just want to know if there is a general method I can use to ...

75. faster way to \n string?

76. String Class Help

Guys how would I go about doing the following. Say I wanted to find the length of a string using the length() method, eg. int get = str.length(); And then say if the length of the string is more than 7 characters, use only the first 7 characters using the method substring. I thought if you started beginning of index is ...

77. Returning String

78. String question

79. call String from another method

Global variables and getting output from methods is one of the basic things in java, im not really sure what your doing wrong but i think you need to go over the basics before carrying on with your Gui. The only other thing i think of is that you havent quite followed my example correctly and still have "String" before "sd" ...

80. How do I use a string to call a functor?

81. Java, output string, getting correct output?

82. String to Object

83. string first name problem

84. reference to string from another class

Firstly you have not explained your problem clearly. If i am correct your process method should be returning a String and hence not be "public void process()" rather "public String process()". As for retrieving this result from another class. Well you have made all your methods static to class.method() will return the value. If your class did not contain all static ...

85. String x and String[] x

86. String help

87. getting string from a Text area

the most important lesson you should get from this is to find the API and learn to read it. It will answer this and many more questions. It will tell you all the methods available for TextArea, and you'll easily be able to select the correct one. Also, lesson 2: don't use == to compare Strings. use the String equals(...) method ...

88. Help- String representation of an object

90. Help with gettin string from different class

public void movie2() { id = 2; title = "Superman Returns"; agerating = "12A"; duration = "154 Minutes"; description = "A new chapter in the saga of our superhero"; } public void movie3() { id = 3; title = "The Hobbit"; agerating = "15"; duration = "133 Minutes"; description = "Lord of the rings prequel"; as you can see...the methods are ...

91. Non-Blocking Writing and Strings

92. filling string with right alignment

I want to fill the String(amount) in right alignment. i have 6 places(column) to fill the amont(digit). Sometimes it may be of 2 charactersor 3 characters 24 234 256788 So, I have to read string from right and fill it also starting from right. Is there any method for this in java? Please suggest

93. Regarding String....

I have a few doubts here. 1)What happens when we say String a ="abc"; ( I think a new String object is created ) 2)In the next if i say String b="abc"; ( I think one more String object is created). 3) Next if i say a==b? it is returning true. why is it so?

94. Truncate the String ---pls help with code

95. using sets with Strings

Hello, I'm in a dilemma here I'm using a Set to store Strings: private Set X; I have a class that receives a String and first check if the string is allready on the set and if not it adds it: public boolean method (V e) { if(X.contains(e.getString()) ) return false; Y.add(e.getString()); return true; } So I got confussed when looking ...

96. String operation

97. problem with get string method

- as you seem to have already noticed your logic is wrong because you call twice before you read the first row. that's okay because you should throw all that away and return a List of objects created from your ResultSet anyway. And you can do away with the opening if in that scenario. - unclosed JDBC resources (ResultSet, Statement, ...

98. Strings

99. Cutting strings

100. program on string