1. string problem coderanch.comOriginally posted by fred rosenberger: a Map might be overkill... since there are only 26 letters in the western alphabet, you could just use an array. iterate through the string, and increment the proper value. Then, when done parsing the string, loop through the array to find which letter has the most. |
2. String class coderanch.com |
3. Immutability of strings??? coderanch.comit works like this brother when you are creating a new string in your program the compiler will check if there is alredy any string with the same name if yes the newly created string will refer to the already created. Butttttt. once you change content of any of the strings a new string object will be created your reference will ... |
4. how to take a series of string from command line? coderanch.com |
5. String coderanch.comIn Kathy's book I fond the explanation sbout the same question: If several reference variables refer to the same String without even knowing it, it would be very bad if any of them could change the String's value. You might say, "Well that's all well and good, but what if someone overrides the String class functionality; couldn't that cause problems in ... |
6. Getting Alpha Portion of a String coderanch.com |
7. Problem sending a string as Http response coderanch.com |
8. Using parenthesis inside a string coderanch.comWhat is the syntax for using a parenthesis inside a string? If I don't put an escape character on it, the compiler thinks its supposed to close a statement outside of the string... but if I do put on on it it says its an illegal escape character? If nothing else I guess I can write the ascii code into a ... |
9. breaking string coderanch.comi have string like this |
10. how can we prove that String class is non mutable class coderanch.com |
11. string alignment, output to screen coderanch.comwell you would have to go through and change the padding for whatever new data your trying to represent. If you had something general that would just handle the spacing lets say alignRight(data) for example it would be easy to call and use no matter what. FYI what im doing is making a paragraph where the user gets to choose the ... |
12. String input with parenthesis coderanch.com |
13. creating string coderanch.comConsider the normal way an object is created with the new operator: new |
14. possible combinations of a fixed string coderanch.comNested for loops are your friend I think. Iterate over the string and for each index reiterate over the other indices replacing each with *. You would skip the index of the one you are on to maintain its position. e.g. if input is "abc" then the first "outer" iteration will use 'a' at index 0. So you iterate over the ... |
15. First element in string coderanch.com |
16. Doubt in Strings coderanch.comHi, The way the strings handled null value is completely different. I was in a mess what had happened to the string. String test2 = null+"test" So you both mean that null in the statement will be treated as a string and in operator overloading the value is concatenated and printed as nulltest. |
17. String reversal program coderanch.comI am stuck on this project that is supposed to accept a text file as an input, reverse the text (ex: Hello there!....!ereht olleH) and then output to another file. So if I run this program using the second file as an input, then text comes back to normal. There are two classes - ReverseLine and a ReverseLineTester. I run it ... |
18. Best way to figure out overlapping of strings coderanch.comThat isn't really an overlap; if you had ABCD and CDEF then the overlap would be CD. You can try putting one String into a regular expression inside [] and the seeing whether you can match the other. But then you would get ABCD matching FEDC on the DC. In the case you mention you would also have problems with the ... |
19. In this code why a new String object is created, than not using println(copyTo)? coderanch.comActually, it would print the same thing. There's an overloaded version of println() that accepts a char[] argument and prints the characters as if they were a String. The reason the code makes a copy of some -- not all! -- of the characters is because it is demonstrating how the System.arraycopy() method is used. The reason that the programmer creates ... |
20. Pixel width of a String coderanch.comIs there anyway to determine the pixel width of a given string? We need to set a length for a javascript menu in pixels dynamically based on the length of the string. The string could be in a number of different languages so we need to dynamically get the pixel width. Any ideas? Thanks. |
21. Making string bold coderanch.com |
22. string interning coderanch.comHere's my understanding of the following line of code. System.out.print(((a+b)==(a+b)) + ","); First, a chunk of memory is allocated for the operand on left hand side of the equality operator and the value of (a+b) is stored in it. Next the operand on the right hand side is evaluated and checked whether the resultant values aleady exists in the memory using ... |
23. Runtime getRuntime() exec(String command) - How does this work? coderanch.comimport java.io.*; public class TestExec { public static void main(String[] args) { try { Process p = Runtime.getRuntime().exec("cmd /C dir"); BufferedReader in = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = null; while ((line = in.readLine()) != null) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } } } This just runs the dir command, captures its ouput and copies it ... |
24. String h? coderanch.comh is a variable; specifically, it's a local variable. A variable is like an envelope with a name written on it. You can put a specific kind of data into the envelope, which you specify when you define the variable. Variables are terribly important in programming: without defining a variable, you have no place to put data and no way to ... |
25. Calling and changing strings coderanch.comHello, I just joined this forum and it looks good. I've had some experience with C++ and as part of my class I'm learning programming through Java. The assignment: I need to create a basic stoplight. Then create a string with identifier "CurrentColor". Then create methods that when used turn one of the lights on and the others off. Then I ... |
26. String Object and GC coderanch.comAre the lost string objects in the String Constant Pool eligible for Garbage Collection? String s = "abc" s = "def"; is the object "abc" eligible for GC. In short, does Garbage Collector runs only in heap or in String constant pool as well. I have read some post on this in Java Ranch, but everyone seemed to have different opinion ... |
27. Mutable String coderanch.comThis all started with SCJP discussion. http://www.coderanch.com/t/426765/Programmer-Certification-SCJP/Argumentdefined-anonymous-class-call But it came to a point that it's no longer relevant to SCJP, so I will continue here. Punit showed a way of making Strings mutable. And after a little hacking, I make an example of possible way of cracking people's data. Look at the following code: import java.lang.reflect.Field; public class MakeStringMutable { public ... |
28. java.util.logging.LogManager.getProperty(String nameStr) coderanch.comBarring the use of reflection to access the private Properties field (called "props"), there doesn't appear to be any way to programatically retrieve an enumeration of configured properties. However, the LogManager API documentation does provide some details about the names of some of the system and global properties, and also some naming conventions. It also refers to the default configuration file ... |
29. Unable to populate String coderanch.comUnable to populate String (Java in General forum at JavaRanch) A friendly place for programming greenhorns! Register / Login Java Forums Java Java in General Unable to populate String Post by: Patrick Boos, Greenhorn on Jan 23, 2009 11:31:19 Hello, I am creating a client/server application that verifies math equations for addition, subtraction, and division. I think I just ... |
30. ? extends String coderanch.com |
31. " within String coderanch.com |
32. string seperation coderanch.comi have a file... now i want to open it and read the data split the data. i cannot use StringTokenizer since i do not want the normal delimiters.... like ,*+ etc. i dont want to use String Tokenizer. this is my file 91997869686** hello-160by2.com(Ad: Have a blog? Use 160by2.com widgets to let readers send free SMS)**"2009/02/05 14:58:36+22"*** 9196379574954** hi sssp-160by2.com(Ad: ... |
33. Need help with Strings coderanch.comI hope someone will take the time to read all this. I really need help and I have no one around to ask except for JavaRanch. I need some help with questions 2, 4 and 5. I created a string but I'm not sure if I'm supposed to do anything with it. Question 4. I just get an error message when ... |
34. String syntax coderanch.comDoes it work at all? Assuming it compiles at all, it is a weird bit of code. If you look at the array initialiser syntax, and remembering that [x] is array member access, please tell us how you think it works. It does compile, but you have a tiny logic error, so please also suggest how you can get it to ... |
35. Cutting off a string after certain amount coderanch.compublic void insertString (int offset, String str, AttributeSet attr) throws BadLocationException { if (str == null) return; if ((getLength() + str.length()) <= limit) { if (toUppercase) str = str.toUpperCase(); super.insertString(offset, str, attr); }else { for(int i = 0; i < str.length(); i++) { if(i <= limit) { super.insertString(offset, str, attr); } } } } |
36. String question coderanch.com |
37. Strings information required coderanch.com |
38. how to subtract two strings coderanch.com |
39. String question coderanch.com |
40. Garbage Collection for String. coderanch.comYou're kind of all over the place on this. There is a "Literal Pool" for strings that you declare in your program. For example: String JOE = "joe"; The string "joe" is ripped out by the compiler, replaced with a symbol and the value moved to the literal pool. The compiler will replace all instances of "joe" with this single reference ... |
41. Query with String statement coderanch.comPerhaps it might help if you break out the code into two lines: public void someMethod() { String one = "abc"; String two = new String(one); } Then it is easier to see that there is one string created on line 2, and another on line 3. Or, if we compile that method, and then look at the resultant bytecode in ... |
42. string extraction by giving position as first argument in command prompt coderanch.comhello , when the user enters the position as args[0] in the command prompt . the program should search for the string at this position and write string found at that position to the file . here is the code . but it is not returning any string public static void main (String args[]) { int index=Integer.parseInt(args[0]); String line ; System.out.println("enter ... |
43. partial string extraction coderanch.comhello all , from the string "MRN 09DE588004180289E0" i have to extract only the 18 digit number after MRN . this is actually present in a output.doc file . I am currently not able to extract that from the file even after using file writer . when i run no output is coming and output should actually be 09DE588004180289E0 on the ... |
44. String and Final coderanch.comThere is a difference between a class being final and a variable being final. Final for a class means that it can't be subclassed. Nothing more, nothing less. Final for a variable (local, instance field, static field) means that it can only can have its value set once - and never again. A final parameter is similar - it can only ... |
45. Getting Incompatible Types java.lang.String coderanch.comHey guys, I am working on a project right now to create a simple library system. I am trying to compile, but I am getting "Incompatible Types; Found : Book; Required java.lang.string" It is on the lines that return b in the available books constructor. Here is the code I have so far: public class Library { Book[] books; int numBooks; ... |
46. Creating a Unique ID from a String. coderanch.comBharadwaj Adepu wrote: But am not sure if this method creates a same hashCode for same string, i have tested this but not sure... If you read the contract of the hashCode method, it states: http://java.sun.com/javase/6/docs/api/java/lang/Object.html#hashCode() wrote: Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must ... |
47. string issues coderanch.comYour question is: "what does 42 + 44 + Foo() evaluate to?... I thought I laid that out for you guy: "86foo" I will try to explain clearer if I can. In the output the integers are being combined in spite of the fact that the method they are being combined with returns a string. That is what is throwing me ... |
48. Need help with Strings.. coderanch.comString mystring1 = new String("Java Rocks"); String mystring2 = new String("Java Rocks"); boolean test = mystring1 == mystring2; boolean test1 = mystring1.equals(mystring2); Results: test is false, test1 is true =========================================== String mystring1 = "Java Rocks"; String mystring2 = "Java Rocks"; boolean test = mystring1 == mystring2; boolean test1 = mystring1.equals(mystring2); Results: test is true, test1 is true =========================================== For the first ... |
49. question on String method coderanch.com |
50. Returning lenght of a string coderanch.com |
51. Running code written in a string coderanch.com |
52. nullpointerexception with String??? coderanch.comNot quite sure why I'm getting this null pointer exception with this toString method. I've looked at it over and over, and don't see a single thing wrong with it. Maybe someone has a sharper eye than me? The output I get is the below, so it never gets into the loop, as my print statement's aren't reached: run: s = ... |
54. changing a 'final String' coderanch.comIf your final reference points to a reference type which is mutable, you can use the values to alter the state of that object.public class Kettle { private int content; private int size; private int temperature; public Kettle(int size) { this.size = size; content = 0; temperature = 0; }//end constructor public void boil() { temperature = 100; }//end boil @Override ... |
55. String related doubt coderanch.com |
56. question on Strings coderanch.comAssuming written inside main String s1 = new String("amit"); System.out.println(s1.replace('m','r')); System.out.println(s1); String s3="arit"; String s4="arit"; String s2 = s1.replace('m','r'); System.out.println(s2==s3); System.out.println(s3==s4); Above program segment produces following output: arit amit false true i thought it will be: arit amit true true I thought that Strings 's2' and 's3' will be pointing to the same String literal "arit" in String constant pool. But ... |
57. Methods and Strings coderanch.com |
58. String Question coderanch.com |
59. Help in String[] coderanch.comHi. i am struck up while performing an operation on the string array. Consider String[] a = new String [5] and another string String[] b=new String[3]. Now all the 'a' contains the values 0-6, and 'b' conatins values 0,1,9,4,7 respectively. So the first element of 'b' should be compared with all elements of 'a' and this goes on till the last ... |
60. doubt in program of String Handling- please review coderanch.com |
61. Getting a lot of "method cannot be applied to (java.lang.string)" coderanch.comI am trying to write a program that simulates a simple libraray. I am having some trouble applying some of the methods to the main method. Here is my code so far: public class Library { Book[] books; int numBooks; String address; void addBook(Book b) { //Adds books to the array of this library books[numBooks] = b; numBooks++; } public boolean ... |
62. String Compressor coderanch.comI have a lab that asks us to compress a single word string that will be entered by the user (the professor). If you enter aabbbbbaaaa = 2a5b4a would be printed. My main problem functionally is that I am having trouble finding a run of letters. I have converted the string entered into a character array. I then cycle through the ... |
63. When Garbage Collector going to removes unused String objects coderanch.com |
64. String execution coderanch.comYou want to dynamically execute the String String h=System.out.println(\"HI\"); as a java command? That is you want some way to say execute(h) and it should execute the SOP and print Hi? I don't think that could be done. If I could execute arbitrary String as code during run time then the Java Bytecode verification would be moot - no point in ... |
65. Using String coderanch.comHi Varsini, in the first case you are creating a object type of string array of size 5. Since you haven't initialized value for elements of array so by default element will get null(which is default for object) in case of int array it will be 0. Now in second case you are creating object of type string array with size ... |
66. General question about the String class - and final classes in general. coderanch.comI have been reviewing the ideas behind the String class, I don't have a question I need help with so much as I want to summarize my understanding to see if I have it right. 1. A string is an object, an instance of the String class. 2. Strings are immutable, A string object cannot change, you can only change the ... |
67. cannot be applied in java.lang.string coderanch.comWelcome to JavaRanch Please note we have a button for putting round code fragments (details here); please use it because the code is difficult to read otherwise. Please avoid any1 and w/o because many people on this website didn't learn English as children and may not understand those contractions: details here. Don't try setting a delimiter on a Scanner, unless you ... |
68. If only one vowel is entered in the string, then that vowel should be diplayed on console coderanch.com1) Have a char or String variable hold the value of the last vowel found, and use this result if count == 1. 2) Simplify your search by changing your text String to all upper case or lower case (player's choice) and searching this string for vowels. 3) If you want to blow your teacher away with a little bit of ... |
69. What's in new String() object? coderanch.com |
70. create a key from a string. coderanch.comYeah, I agree. It is better to have the objects compare themselves -- or even using a comparator -- than to convert it to a string for comparision. But, to answer your question... There is no free lunch here. You can shorten a string, but you will lose data, and hence, accuracy in comparison. Generally, shortening a string is useful, if ... |
71. A question about String operation coderanch.comThe replace() method should work. The replaceAll() method, like the split() method, takes a regex -- and the "(" has special meaning, in a regex. I really recommend that you read up on regexes, it is really a powerful tool. And going to a forum to figure out the regex to create for the replaceAll() methods is not very effective. Henry ... |
72. String Builder Class coderanch.com |
73. String vs Object coderanch.comTo get back to the original question: You can reference methods of an object based on the variable type. For example, if you store a String in a String variable, you can run String methods on it. If you store the String in a variable of type Object, then you can only run Object methods. For example: String s = "hi ... |
74. Best Way to Turn Query to String[][] coderanch.comA friendly place for programming greenhorns! Register / Login Java Forums Java Java in General Best Way to Turn Query to String[][] Post by: Al Johnston, Ranch Hand on Aug 24, 2009 21:50:19 Hi, I'm trying to build a socket that saves time when users query on any of our web sites. The way it works is to hold ... |
75. how to use \ in a string coderanch.com |
76. Please explain |
77. Doubt in String's coderanch.com |
78. Incrementing alphanumeric string coderanch.comI'm sorry...I was not clear about what I meant by incrementing. I want to add one, so that AAA123 turns into AAA124. At first I considered incrementing the letters and numbers separately, but that will not help me in the case of AAA999 to AAB000. Clearly I need to treat the entire string as one number. |
79. where to see the source code for java.lang.String coderanch.com |
80. Strings Immutability coderanch.com |
81. String replacAll is not working coderanch.com |
82. RE:String handling in java coderanch.com |
83. Struggling with String Processing task coderanch.comI've dome my share of string processing, but for some reason I can't get my head around this one. Here is the task. I start with a string which contains a mixture of letters and 1's. I wish to replace any consecutive subsequence of 1's with a single digit which is equal to the number of 1's in the subsequence. Now ... |
84. please found out the output for this simple string program coderanch.com |
85. String Manipulaton coderanch.comI have attended one interview and there was a question on Strings... how many objects are created in the following code? String s1=new String("Hello"); String s2="hello"; String s3="hel"+"lo" i know that Strings are immutable and it refers to the objects in the pool. If new keyword is used, then it will create a new object and will not refere to the ... |
86. String Interpretation. coderanch.comHi, I am just starting a pet project for which i need some guidance and help. I have been programmer in the past but not done much programming lately, so i do need to brush up on some stuff. The question I have is if someone can direct me to some reading materials, tutorials, existing APIs, etc. for the following problem. ... |
87. String assignment coderanch.comNot quite. The first statement creates one String, which is created at class loading time. That is the "abc" on the right. Then it applies the name "s" to it. You have one String. This is independent of whether there is a String "r" or not. If you had another reference as John de Michele showed, you would still have one ... |
88. String!!!!! coderanch.com[deleted] Yeep just saw the previous post by someone else...Though I do not understand the explanation.... Anyhow thanks for your reply...I think I will just take it for granted that there are two ways of doing the same thing without any potential benefits...except in one the string is left on the heap for "potential" future use and in another it isn't.! ... |
89. String object ? coderanch.comEdward Chen wrote:In the code below, x1, x2 will point to different object ? I think because String is immutable, keep a string pool, x1, x2 should refer to same object , is it correct ? It has nothing to do with immutability or some "string pool". It's very simple. in Java each different String literal, like "abc", is represented by ... |
90. string doubt coderanch.com |
91. Regarding String Object coderanch.com |
92. Initialising objects and Strings in local methods coderanch.com |
93. Building a class which initializes abject like String class? coderanch.com |
94. How many String objects are created when the following method is invoked coderanch.com |
95. String immutability coderanch.comclass Assignments2 { int var1; public static void main(String[] args) { // --- Assignments2 assignments2 = new Assignments2(); Assignments2 assignments = assignments2; assignments2.var1 = 77; System.out.println(assignments.var1); assignments.var1 = 79; System.out.println(assignments2.var1); System.out.println("---"); String x = "Java"; String y = x; System.out.println("y= "+y); x += " Bean"; System.out.println("y= "+y); // --- System.out.println("---"); Integer i = 32; // or just Integer i = 32; ... |
96. Minor Detail - for(String b: sa).. what's the 'b' for? coderanch.com |
97. doubt with string predefined method coderanch.com |
98. String predefined method doubt??? coderanch.com |
99. Help with String class coderanch.comi keep forgetting to write back to thank people for helping me... didn't want to bring back the topic. Thanks to all!! I'm having trouble with a program. I'm basically checking to see that a SSN is inserted correctly into this format "DDD-DD-DDDD." If its not in that format, then it returns false. My question is, what kind of method or ... |
100. String class: simple yes or no question here coderanch.comthe 'assignment' operator in java is the '=' symbol. you use this to assign a value to a variable. when you decleare a variable, you must have two things - a type and a name. for example, you could have a 'double' type variable named 'fred'. you would declare it like this: double fred; if i then wanted to assign a ... |