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 ... |
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 ... |
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? |
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. ... |
|
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? |
|
|
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. ... |
|
10. string forums.oracle.com |
|
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 ... |
|
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 |
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 that...now 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 ... |
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(System.in); String customerType = sc.next(); 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 |
|
|
|
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 ... |
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 forums.oracle.comjustinhol 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. ... |
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 ... |
|
27. Strings forums.oracle.com |
|
|
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 ... |
|
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 ... |
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, ... |
|
Hi Guys, I was just glancing the JLS when I came across this definition of [Objects|http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html] : 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 ... |
|
This is Java 101. You need to start here: [http://java.sun.com/docs/books/tutorial/java/index.html] == 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 ... |
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 ... |
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: ValidatePassword.java:79: 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 ... |
|
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 ... |
|
|
|
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 ... |
|
|
|
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 ... |
|
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 ... |
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 ... |
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 ... |
|
|
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? |
|
|
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 + ... |
|
|
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 = ... |
|
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?? |
|
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 ... |
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 ... |
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 ... |
|
|
|
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 ... |
|
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 ... |
|
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 ... |
|
|
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" ... |
|
|
|
|
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 ... |
|
|
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 ... |
|
|
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 ... |
|
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 |
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? |
|
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 ... |
|
- as you seem to have already noticed your logic is wrong because you call rs.next 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 forums.oracle.com |
|
|