String 19 « string « Java Data Type Q&A

1. write square bracket in string

Ok. sorry my bad, i thought i just needed to ask about the [ so i didnt post my exact code. Which was actually: input = token[1].split("["); But i think i found a solution input = token[1].split(" ["); Double escape And i even learned to post the actual code. /Carsten Edited by: Carsten78 on Oct 26, 2007 1:19 PM

2. Strings

3. String

The RHS of the first one gives a reference to a String object that already exists in the constant pool, and is the correct way to do it. The RHS of the second one creates a new String object and gives a reference to that new object, and is the wrong way to do it.

5. problem in retriving string

6. string handling in java

I think somehow Java just can't go to the next line and print out the text in the .txt file and cramp up all the letters together even after using "\n" and I have encountered this many times. Even the JNotepad or some sort of notepad sample provided by Java in the jdk samples bundled together with the JDK you download ...

8. NullPointerException on String methods

public static void main(String[] args){ DateWorker dateWorker = new DateWorker(); String m = dateWorker.getMonth(); String dm = dateWorker.getDayOfMonth(); String dw = dateWorker.getDayOfWeek(); String y = dateWorker.getYear(); System.out.println("day of week " + dw + ""); System.out.println("day of month" + dm + ""); System.out.println("month " + m + ""); System.out.println("year " + y + "");

9. Using "\" in String

10. String Inputs

11. Need Help with String

12. String extraction

13. string problem

class forloop { public static void main(String arg[]) { byte ascii[]={65,66,67,68,70}; String s1=new String(ascii); System.out.println(ascii); } } i use jdk1.4 , when i run this program i get out put [B@cac268 but according to me the answer should be ABCDEF (byte-to-character conversion is done by using the default character encoding of the platform.) this is an example in complete reference (5th) ...

14. Detecting Strings LtoR or RtoL

Hi All I have a String that may or may not be in Arabic or some other Right to Left language. I do not what this string will be at compile time. I need a reliable way of detecting if this string is Left to Right or Right to Left at run time so i can change my layout to suit. ...

15. string tokenizing problem

16. Mask the Password string

Nothing you can do will prevent the user from reading the password when passing it as a GET parameter. You could encrypt/hash the password and then Base64-encode it, but all that will do is hide the literal text of the original password, the Base64-encoded text can still be used as the password in that case. Unless you switch to POST, I ...

17. How to use string

18. String instances

Only one instance is created above, by executing concat. Concat will always create a new instance. (Well, I suppose it's possible that if you're concatting the empty string "", that concat would just return the original, but I don't know if it's implemented that way. You can look for yourself if you're interested.) What I said, though, is that not every ...

19. String Compression

It's easy. Compress: write number of same characters then character itself. Decompress: write as many each characters as specified by each first character using character specified by each second character. And main: think at least one atempt to do your homework before posting here. Thanks. PS.: If I'm under wrong impression about you then post code you already have and everibody ...

20. Problem in String Decompressor

Good Morning Friends I have a compress data with type byte[]. Whenever i tried to write compress data into buffer it goes into infinite loop in some case. For example in 1000 file 2 or 3 files goes into infinite loop. That means those byte[] can not reach at its end of file. MY Java Code is : public static byte[] ...

21. Instantiating object using String Varriable

22. Need to change a string.

System.out.println( "Please enter hours worked this week:" ); hours = input.nextDouble(); System.out.println( "Please enter pay rate of employee:" ); payrate = input.nextDouble(); if ( hours < 0 ) { System.out.println( "Please enter a positive amount for hours worked:" ); hours = input.nextDouble(); } else if ( payrate < 0 ) { System.out.println( "Please enter a positve amount for the pay rate:" ...

23. String help

24. Making Strings an object of a class

A String is a String and a Customer is a Customer. Casts are checked at runtime even if you can smuggle the casting past the type checking of the compiler. You can of course provide a way to have the String representation of a Customer or how to convert back from it into a Customer.

25. String condense

26. strings

27. doCommand(String s) ?

Hello, i'm trying to write an applet that paints functions in a Canvas. It's quite simple: i use JTextField for changing values. For example the layout is like this: JLabel("X^3"),JTextField("insert x^3 value"), JLabel("X^2"),....... then i use. xCoeff = ((Integer) textFieldX.getText()).intValue(); and: y = xxxCoeff * x * x * x + xxCoeff* x * x + xCoeff * x + coeff. ...

28. To measure string in kb

29. String optimising

30. writing a string

31. Invisible string

32. String[] vs String ary[]

33. String.getBytes();

34. petty string

35. transform string from one codepage to another

If there's no output at all, it's probably because you didn't flush the stream, but that's not your real problem. The console is going to decode the stream according to the encoding (or codepage) it's been configured with. Specifying the encoding the way you're doing won't change the console's codepage, it only affects the encoding of the text you're sending it. ...

36. string B

37. String

38. String name

39. String problem

40. help with java strings

41. Have a JTextComponent directly modify a String

I'm at a complete loss, here. What I need to do is have a JTextComponent basically display a String and any modifications to the text in the JTextComponent will mirror in the String - so it's like they're the same. I've tried several approaches to this... First try I used a custom DocumentListener (applied to the JTextComponent) which would intercept any ...

42. Blank string

43. Generate fixed-length unique strings

Hi all, I'm trying to generate 16 byte unique string from two input strings. Essentially, the unique string will be used as primary key in the database. The two input strings are (siteUrl, productId) in which siteUrl is the url of a website which has one or more productId. Each productId in a site is unique but there might be duplicate ...

45. Which is better and why a = new String("AA") or a = "AA"

Actually we have a special memory for storing strings called "stringpool" If we use a=new String("AA") two objects will get created,one in the string pool and another in the memory,and the reference variable will point to the object in the memory not to the object in the pool. If we use a="AA",only one object will get created in the pool and ...

46. String

ok I'm still stuck on this problem becuase the website is a little different than i though... i have a 2-D array which contains the row and column (table[row][column] ) in column 1 is the date and the only thing i want to change but i have 2 different formats...7/26/2007 9:00:00 PM and July 09 2007 9:00 PM any suggestions on ...

47. String

48. best way to break down a string?

Hi. I am wondering, what is the best way to get all the substrings with a patten from a string. Here is an example. String str = "|hello|123456|a,b,c,d,e,|" i want to get all the substrings between 2 consecutive "|" symbols. hello 123456 a,b,c,d,e, is there a build in method to achieve it? Read it char by char is the only way? ...

49. How to get recors from String

50. String outof bound range-1

public ArrayList getParentLabel(String file) throws IndexOutOfBoundsException, IOException { Label in=new Label(); Stack stack = new Stack(); String lastToken=null; BufferedReader br = new BufferedReader(new FileReader(file)); // read text file by buffered reader String line; while ((line = br.readLine()) != null) { String lastPath = line.substring( line.lastIndexOf("/")); lastToken=lastPath.substring(1,lastPath.length()); al.add(lastToken); // add token to arraylist System.out.println("ess="+al); } br.close(); return al; } }

51. Question on Strings

Hi to all, It is very clear before this i want to explain you the diff. between String s=new String("1234"); and String s1="1234"; In the first case s is created as a object and in the second case s1 is created in string pool which is maintend by JVM. String s1="1234"; String s2="1234"; if we create same string twice in stringpool ...

52. method content to string

53. String problem

I am developing an AWT application for some handheld device and can only use AWT to develop it for perfomance and constraints as well. So, i need to populate paired value, for example barcode and quantity into java.awt.List. As general, List only allows String as list item (list.add(String)) . However, it is very hard to have the table or column behaviour ...

54. String Scraping from Websites

I'm looking to start a new program from scratch where I can scrape the contents of a website to get hotel prices. How would I go about doing this and can anyone point me to any example pages on sun docs? I can't seem to find any. I want to scrape these details and load them into relevant textfields, then calculate ...

55. A slightly unusual String question

Hi everybody, Does anyone know if there is a limit to how long Strings can be? I'm parsing an html file and the opening and closing paragraph tags are not always on the same line. The only way I could think of to make sure I parsed out the paragraphs correctly was to squish the whole HTML body (which is very ...

56. String problem

BufferedReader reader = new BufferedReader(new FileReader(new File(filie))); String line; while ((line = reader.readLine()) != null) { StringTokenizer st = new StringTokenizer(line, "/"); // System.out.println("st"+st); String path = st.nextToken(); String url = st.nextToken(); String perm = st.nextToken(); String label = path.substring(path.lastIndexOf("/"+1)); // I cannot compile after this line. Can anyone explain me why .I am getting following exception. String pathToNode = path.substring(0, ...

58. Strings problem

60. How to show a g.string ?

ive been building business apps with j2ee for my university projcts but i never really did something like this before. You guys can laugh all you want (hey even i do it sometimes about myself =D ) but im here to learn from my mistakes. Anyway ill read up the tutorial and see what i can manage to do. but if ...

61. filter string

62. Getting a method or object from a string

Is it possible to take a string (ex. String str = "myObject";)and get the void/string/int/boolean (or better yet, any object) of has the same name? Just an example to clairify: I want to take something like this: String str = "myMethod"; And (somehow) get this: private void myMethod(arg arg) {... I'm sure there's a way to do this, but maybe someone ...

63. new String overriding the previous String

64. i have a minor string issue

65. String Vs Interger/Character

Why do String class has special treatment than any other classes like Integer, Character? for ex - when we write String str = "abc"; (it is valid and actually creates object) but when we write Integer in = 10; (not valid) why so ? whats so different in String class.? Is any one can help me out ? Thanks in advance. ...

66. String

67. Problem sending string through serial port

//Send the stream try { outputStream.write(messageString.getBytes()); } catch (IOException e) { System.out.println("Error by writing to the serial port");} }//End of Transmit } I am preatty new to java programming, but for some reason i suspect some sort of charset problem to be the reason for my program not working. I don't think that the command is sent out in the correct ...

68. Pull data from a string

69. 'java.lang.String[]' incompatible with 'E'

70. execute code from a string?

I have a Java program that draws lots of different types of curves. I need to program how to save a drawing to a file. It would be easiest to make a file that has the string of the code which recreates the drawing. Is it possible to execute the content of a string? A trivial example would be you declare ...

71. Strings are confusing and clarity required from group

The JVM holds a (small?) cache of literal strings so String s1="Computer"; places "Computer" in the cache and String s2="Computer"; gets the same instance from the cache so both s1 and s2 point to the same String object. String s3=new String("Computer"); creates a new String that has the same contents as the others but is not the same instance.

72. Why won't this see the 'string'.. basic java help.

Ok so i don't want to create a new thread.. but once i compile the following code i get the following error. One I haven't seen before. !!Code in following post!! Won't let me add in a 'edit'!!! Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind ex out of range: 0 at java.lang.String.charAt( at bah.main( Message was edited by: Scustoms

73. How many strings can Java handle?

If I have String MyArray[400000]; Is there any danger that Java will have a stack overflow or some such? What kind of overhead is there with the String object? I heard the stack is 64 MB -- is that the case (as of JRE 1.6)? 64 MB divided by 400,000 is 160 bytes -- Matthew

74. need some help with the string

75. Write the contents from String

The task is as follows. Read a text file(large file) line by line. After some string manipulations I are getting a new line, ie a new line for each line. Each new line is appended to a StringBuilder or StringBuffer. After reading the entire file I am writing the contents (which is in the StringBuilder or StringBuffer) to the existing file. ...

76. How many string tokens do I have?

77. how can i goto a string in a textarea (urgent)

/* * else if (e.getSource() == saveButton) { int returnVal = fc.showSaveDialog(Editor.this); if (returnVal == * JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //This is where a real application would * save the file. // log.append("Saving: " + file.getName() + "." + newline); } else { //log.append("Save * command cancelled by user." + newline); } //log.setCaretPosition(log.getDocument().getLength()); } */

78. unequal strings

80. comapring two strings

81. String Problem

82. Using Strings

This creates a new String-object that points to a String ("Maruthi"), and a reference s will be pointing to the new String-object So it will function the same, but the second option s1 will get two references. ( don't worry). Example: There is another important issue.. String s1 = "Maruthi"; String s2 = "Maruthi"; String s3 = new String("Maruthi"); Now s1 ...

83. New charater Strings

If you only want to work with shorts, then you can do that rather than the dynamic approach, but you won't get as good compression - you'll be writing write 16 bits when you only need to write 9. If that's not a problem, then use the writeShort() and readShort() to read and write them consistently.

84. Problems With Strings!

what i want is the the bit ((hex.charAt(j)).indexOf(reference)) simply to return the character at the index of 'j' in the string 'hex' and then to find the index of that returned character in the string 'reference'. When i compile the code as it is above, i get the following error: javac char cannot be dereferenced total = total+(Math.pow(16,j))*((hex.charAt(j)).indexOf(reference)); ^ ...

85. simple string question

Use Vectors for storing URL. Before adding any new url you can check is this available or not. If not then add the new one. Also if you want to add other information e.g when this was accessed and who accessed can also be stored. Create a class with these information along with the url and store that class object in ...

86. How to add " to a string.

87. help in strings!

89. Separate String

Ok, So I have taken your advice and have now learned how to separate and put back together a string. I now have another question, is it possible to say take that string and, possibly using StringTokenizer or some other way, separate that string into separate blocks say every five characters or so. Again thanks guys.

90. String objects

91. Easy String[] question

92. Flipping a string

93. Problem with writing UTF8 Strings

Hi, thanks for the reply! Yes, I understand that a UTF8 string written to a DataOutputStream is prepended by a 2 byte length indicator (ie a modified unicode implementation), however, that should have no bearing on the readUTF, which looks at the length first and decides how many bytes to read in. The program works fine in when writing strings less ...

94. String getting cloned automatically. Why?

When I change an element of buffer2, lets say buffer2[0].append("something"), it changes the buffer1[0] as well. I understand that. Now how to overcome this using clone? I cannot override the clone() method of StringBuffer, nor can I override the imlementation of Array's clone(). Does this mean that cloning cannot help arrays of mutable objects?

95. cutting a String in two digits pairs?

96. creating an object, named from String contents

Hi, Im currently trying to populate multiple HashSets with objects named by the user, in order to automatically avoid duplicates and so I can use set functions. Im currently stuck on creating an instance of a class with the name of the instance being the value held in a String. Any suggestions would be much appreciated.

98. Generate a class from a string

yes, it can be done. you can spit the string out to a .java file, and compile it either by spawning a new process to run javac on it, or you could use the javac facade in tools.jar, or I believe - but may have been misinformed - that the javac facade is in the JDK itself as of 1.6. you'd ...

99. String help

Well, think about what you're doing. If you have the String "Hello" and want to move "Hel" to form "loHel", you will have to move the first character in the StringBuffer X number of times, since you are appending the character to the end. You are moving the character at 0 the end, which works, but then you're moving the 2nd ...

100. Strings