format 2 « Development « Java Data Type Q&A





1. Split string and delete every second space in java    stackoverflow.com

I have log data in a raw file. It looks like this:

"2 A U W 2 0 1 1 1 1 1 6 0 0 1 0 0 0   ...

2. How to convert binary data into string format in JAVA?    bytes.com

Hi Dheeraj Joshi, I have no idea what are their format,how could i know it? by the way, i'll gonna check the link you gave.. Thanks a lot. Mark Tan

4. Format String in commas    coderanch.com

... Assume the incoming string is a big number. ... The DecimalFormat in Java has a limitation to format a big number. 95% of problems are solved by clarifying your requirements. Let's filter out the things that are definitely not requirements. "incoming string is a big number" - that statement can never hold true. Is it a String? If ...

5. Java 1.5 String.format    coderanch.com

Does anyone have any experience with the new format method in the String class in 1.5. I have several decimal numbers (money) and need them to align on the decimal point in columns. I.E. 12.45 11.23 3.90 2.34 23.90 34.53 I'm hoping there is a format string I can pass to do this rather than figuring out how long each number ...

6. Formatting string for printing    coderanch.com

I am trying to print out something using my java program. I was the printed page to be 2 colums. For this, I need some mechanism where i specify that it should print in 2 columns and it has to print in the first column and continue in the second I dont have any idea how this can be done, can ...

7. string format (with mask?)    coderanch.com

hi there, i have a string, for example "127.0.0.1", which i need in this form: "127.000.000.001" (filled up with zero). right now i'm working with a loop and a set of conditions, but i'm sure there is a more elegant (=efficent) way. i played with MaskFormatter("###.###.###.###"), but I'm not sure if this solves my problems. Even if i need this conversion ...

8. Can I use String.format?    coderanch.com

Hi Everybody, My GUI accepts a string from the user i.e the time offset...it should be in the format +/-hh:mm...but a bug has been reported because there is apparently no check for the format...it is accepting even a string like "abcd",but not performing(obviously!) the required conversion. Can anyone suggest how to accept a string only in the form of +/-hh:mm and ...





10. MessageFormat.format issue    coderanch.com

Hi, I have an application that uses MessageFormat.format. This works well in most cases except when I try to enter things like

17. Formating number-Inputs by locale    coderanch.com

18. Formatting a String    coderanch.com

19. storing strings in a specific format    coderanch.com

20. String formatting issue    coderanch.com

Hi, I am using Java 1.5. I am facing a formatting issue. Following is the code which I am trying to compile. public class fibonacci { public static void main (String args[]){ int fib1 = 1; int fib2 = 1; int fib3; String s; System.out.println(); System.out.println("The first 25 Fibonacci numbers:"); System.out.println(); System.out.println("Fibonacci number 1: " + fib1); System.out.println(); System.out.println("Fibonacci number 2: ...

22. String.format    coderanch.com

23. DecimalFormat is not setting the format for is_IS Language    coderanch.com

Hi, Do any buddy have idea about the applyLocalizedPattern(fmt) method from class DecimalFormat. My problem is when I am setting the format for en_US it is setting the format (ex: $#0.00 for USD) properly but the same is not working for is_IS language code. like for en_US if money is $21.0 then it is formatted to $21.00 This is ok But ...

24. Formatting output of a string    coderanch.com

Start off with something like System.out.printf("%20s%25s%n", name, address); See how that works. Try the flags shown in the Formatter class. There are a few examples in the Formatter class API, which I think I quoted earlier. You can set up a Formatter to format to a file (see the Formatter class constructor) and write a similar format with the format method, ...

25. Formatting concatenated string objects    coderanch.com

I am trying to return a string made up of several different concatenated variables of multiple types to a different class. This part is working just fine, the problem is I want the data to show up in neat organized columns in the output from the second program. The first column of the output is made up of 4 digit numbers...no ...

26. Doubt in String formatting    coderanch.com

I want the output to be in this format: Al is 45 years old Al23455 is 45 years old Al23455 is 459999 years old public class NewStringFormatting1 { public static void main(String[] args) { int a=10; String name="sai"; //String s=String.format("The value of integer is %d ",a); //String s=String.format("The name of our fool is %s ",name); String s=String.format("%s-10s is %d years old", ...

27. How to convert String to EBCIDC format    coderanch.com

28. How to convert excel sheets exponential cell format to java string    coderanch.com

Hi All, I am facing a problem in importing excel sheet in java application and intern inserting rows in oracle database. One columns in excel sheet is holding numeric value and data length of that particular column is 17 digits. Excel automatically converting the value of that column in some format (seems exponential) i.e. 12345678901234500 becomes 1.23E+16. I am parsing this ...

29. About String.format()    coderanch.com

30. java.util.logging: MessageFormat-style parameters or String.format()/printf style    coderanch.com

Within the context of logging performance and efficiency, an advantage of the MessageFormat example over the String.format is that if logger.isLoggable(Level.FINER) is false, the MessageFormat example may do less work. It will create a new Object array with the values of transactionId and will call getName like the String.format example, but it may skip the string formatting. MessageFormat may be a ...

31. How to change format the following string?    coderanch.com

public class NumberConverter { public static void main(String[] args) { String someDynamicValue = "3.00"; if (someDynamicValue != null) { int dynamicValueIndex = someDynamicValue.indexOf('.'); int dynamicValueLength = someDynamicValue.length(); if ( someDynamicValue.endsWith("00") ) { someDynamicValue = someDynamicValue.substring(0, dynamicValueIndex); } else if ( someDynamicValue.endsWith("0") ) { someDynamicValue = someDynamicValue.substring(0, dynamicValueLength - 1 ); } } System.out.println("converted value is---->" + someDynamicValue); } }

32. Aliter for string formatting - Which is best approach?    coderanch.com

[size=12][color=black]Hi, I am right now looking for a best alternative for the below approach: I need to format a set of values from DB to be separated with a pipe('|') delimiter (for each record). Right now I am doing string concatenations as such: final String PIPE = '|'; String record = value1 + PIPE + value2 + PIPE + value3 + ...

33. String.format questions    coderanch.com

34. center a string in padding using String.format    coderanch.com

Say I want to output pascals triangle and have it LOOK like an equilateral triangle. I have some code: for(int t = 0; t <= stop; t++) { for(int r = stop; r >= 0; r--) { temp = (r > t ? "" : String.format("%7s", chooseK.nChooseK(t, r))); part2 = part2 + (r > t ? "" : String.format("%-7s", temp)); } ...

35. find the format of a string    coderanch.com

hi, Can any one tell me how can i find out the format of a String i.e., which font is the String using and what is the font size of that String. i'm reading that String from a file and to reproduce it i need al that format stuff. Can anyone please help i searched a lot but didn't find anything ...

36. StringTokenizer output formatting    coderanch.com

Hi, Im trying to build a string tokenizer, that scans through Strings stored in a StringArray, and removes delimiters. (.,?!<> etc etc) But using the standard ".hasMoreTokens" and ".nextToken", as with ".hasMoreElements" and ".nextElement", When i print the output, after tokenization to the console, it is removing my delimiters, but printing one token per line. Is there any way, or a ...

37. String.format() cum vsprintf()    coderanch.com

Hi Russ, Welcome to JavaRanch! I think you may be making life much harder than it needs to be, because String.format() is pretty much interchangeable with vsprintf. Maybe I'm missing something, though, and you're trying to go after some subtlety that's being lost on me. The varargs passed to buildStatement are all packaged into an array; the parameter "objects" holds that ...

38. String formatting in JDK 1.4.2    coderanch.com

Hi, I need to format Strings to be of a certain width. Could anyone suggest any in-built methods for this? I've seen some String.format() method stuff but it doesn't seem to exist in JDK 1.4; only JDK1.5 and above. There's surely gotta be a better way than, say, tabbing !? Thanks, Raksha

39. format strings and unexpected output    coderanch.com

40. How to convert Localized formatted String in Amount?    coderanch.com

Hello All, I have once scenario where I need to convert localized string amount to parse and make it long amount. Example: In russia, people write 1000 as "1 000". Now what I need to do is to parse this "1 000" and get 1000. Is there any way in java, which can identify if the particular string is localized price ...

41. Definition of "#" in a format string    coderanch.com

I have a need to left-pad a java string with a number of spaces that depends on my data. I looked for things to do this and found the following: public static String padLeft(String s, int n) { return String.format("%1$#" + n + "s", s); } So now I'm trying to figure out what the "#" means. I looked up Formattable ...

42. String formatting in TextArea    coderanch.com

I assume when you said that your semicolons don't line up, you meant colons. I also assume you want to see multiple rows and that the columns in each row should line up. What font are you using to display the text in your console and TextArea? Is one font fixed width and the other not?

43. String.format() problem    coderanch.com

45. String.format not in javadoc    java-forums.org

Bonjour pourquoi je ne trouve pas la fonction de class String.format trouv sur java.sun.com/docs/books/tutorial/java/data/strings.html dont voici un extrait you can write String fs; fs = String.format("The value of the float variable is %f, while the value of the " + "integer variable is %d, and the string is %s", floatVar, intVar, stringVar); System.out.println(fs); dans la doc de la class String sur ...

46. Convert String to Time format    java-forums.org

Hi there. I am new to java and am currently facing a problem with converting a string to time format. Here is my code: String str = "09:00:00 EST" ; DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss z"); System.out.println(str); try { Date df = dateFormat.parse(str); System.out.println(df); } catch (Exception e) { System.out.println(e.getMessage) } Output: 09:00:00 EST Thu Jan 01 19:30:00 IST 1970 I ...

47. Help with checking for a certain format in a String    java-forums.org

I am creating a program that reads a text file of phone numbers. I have to make sure the phone numbers are in the format of xxx xxx xxxx or xxx xxxx. I can't figure out how to check for this format in the constructor. Can someone help me by writing out a pseudocode for this procedure? I don't want the ...

49. Text/String format..??    java-forums.org

Hello guys, I'm new in this forum and JAVA... OK, here is the case. I want to build a Library Information System. I need to add BookSerialNumber (BSN). This BSN format goes like this : YYYY-CC-DDD. I'll explain it, YYYY = Year of the book published, CC = Category of the book, DDD = Digit count of the book according to ...

50. Error when using String.format method    java-forums.org

Hi, Hopefully I've posted this question in the right forum. I'm new (Obviously) so please bare with me. I'm trying to create a subclass that contains a public String toString. But when trying to use the method "return String.format(...) I'm getting an error stating, " cannot find symbol, symbol: method format(java.lang.String,java.lang.String,doubl,jav a.lang.String,double) Location: class java.util.Scanner" I've imported a util.Scanner and created ...

51. Formatting Strings in Java    java-forums.org

52. String formatting    java-forums.org

54. Display a '%' when using String.format( )    java-forums.org

I am writing a program where I need to display the percent symbol '%' in a GUI using String.format( ). Since % is used as the indicator to place args in the String I can't figure out how to display '%'. example: float percent = 20; String Sentence = String.format("You are %,.2f done.", percent); this would only display 20.00 How do ...

55. Pls help to print string in given format    java-forums.org

56. Formatting a string    forums.oracle.com

Hello All Is there a way I can use format specifiers with variables? OK so I need to format a string to be a certain length equal to the longest string I am using. So what I would like to use is something like: %xs where x is the number of the length of the longest string I have. So if ...

58. need help in the String Format method    forums.oracle.com

60. How to format a string?    forums.oracle.com

61. Converting String to a Time in 24h format    forums.oracle.com

Hi people.. Supose i have a String like Time1= "16:30" I need to convert this into time and Suppose after conversion NewTime=16:30 where newtime is a variable of type time, i need to use this as a Parameter in a Query Like Query="SELECT * FROM Table1 WHERE Time='NewTime'; { //results of Query } What i want to Know is that The ...

62. Formatting a String    forums.oracle.com

0. create a StringBuffer 1. append first group of three digits 2. append a dash 3. append second group of three digits 4. append a dash 5. append third group of three digits Note that the simple and obvious way of doing things is very often the best way! I suggest you leave the complex stuff to the complex people, and ...

64. Verify a String is in the right format    forums.oracle.com

String newYear = JOptionPane.showInputDialog(null, "Please enter the year for " + newTitle); if (newYear == null)&&(newYear ==?????? ) I need help to make sure the user's input is a valid year. The bolded question marks are where i think i need to put something but i think i need to change the string to a int or something before i can ...

65. String format dynamic padding    forums.oracle.com

String.format("%08d", myInt) will return a string 0 padded to a width of 8. But is there a way to have the amount of padding determined from a variable instead of having ot hardcode 8 in there? So if my program determines the padding needs to be X it can just use X in the String.format() method somehow? I didn't see it ...

66. string format    forums.oracle.com

67. how to use MD5 format of string    forums.oracle.com

68. String.format question    forums.oracle.com

isnt the second parameter for a string though... i mean its not for a string when you put d in there because i think thats for an int but i need to pretty much know how to center a certain word within the length of len with a | at the end...

69. String Formatting    forums.oracle.com

I have a list of firstnames and lastname with salary and all.. I have to print them in a perticular way..but I have to use toString method lname1 and 1name 2 should aligned or salary should be aligned Output should be like Monica Monica 3000 Jonathan John 2000 is there any way I can format the string ? thanks

70. Quick One, Format String length..    forums.oracle.com

71. String formatting    forums.oracle.com

Hi I have a string which I want to split into 80 characters each For ex: If I have a string about 120 characters, I need to split into two strings - the first having 80 characters and next having 40. Similary for 160 - two strings 80 each. for 161 - 3 strings, 80, 80 and 1 Any ideas

72. Silly question about MessageFormat.format    forums.oracle.com

73. String formatting    forums.oracle.com

74. Formatting strings    forums.oracle.com

No, I have not tried anything like creating my own String class. C:\Documents and Settings\Peter>java -version java version "1.6.0_17" Java(TM) SE Runtime Environment (build 1.6.0_17-b04) Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing) C:\Documents and Settings\Peter>javac -version 'javac' is not recognized as an internal or external command, operable program or batch file.

75. String Format    forums.oracle.com

Hi, I have to process a string for a specific format. Basically, need to check if it confirms to the given format. The string I usually get is a numeric string. However might get some invalid values. Format: "DDD.D" , where D is any digit from [0-9] Input is String Output: boolean "100.1" ---> true <----- "1.123" ---->false "-23" ----->false "java2" ...

76. Format String with pattern    forums.oracle.com

Hi Folks, my Problem is that i need to format a String by using a pattern. The Input String is like "20081208" and the Output String has to be "2008-12-08". I could simply do this by using String.substring but i think it's not that elegant. Also i found a way by doing it with SimpleDateFormat. But it needs to much lines ...

77. How to convert Localized formatted String in Amount?    forums.oracle.com

Hello All, I have once scenario where I need to convert localized string amount to parse and make it long amount. Example: In russia, people write 1000 as "1 000". Now what I need to do is to parse this "1 000" and get 1000. Is there any way in java, which can identify if the particular string is localized price ...

78. String formatting!    forums.oracle.com

Hello all The problem goes like this --> I have to interpret and execute the commands provided by user as a string. Here, _=space action_object1_object2 Now if the user puts input as -->object1__ object2(double space), it should be treated like one object. i.e. one space = different objects more than one space = same object Can anybody provide me the logic ...

79. Can String.format reuse 'compiled' form of format string?    forums.oracle.com

True, but not to point. To build the report, I'm creating strings from other strings through the formatter. An estimate of the amount of max memory allocated is the sum of the input strings, output strings and overhead of the formatter. The overhead of calls to the formatter far exceed the sum of input and output string. Also, the memory of ...

80. Which is best? [String.format(...) or "" + x + ""]    forums.oracle.com

Also, if you ever need the += to concatenate strings, then you should really consider StringBuilder. It will be faster, especially in huge loops. This because the += will implicitly create a new String in the pool. If you only use the +, then you don't really need to worry about performance. The compiler will optimize it for you.

81. convert string YYYY-mm-dd to dd-mm-yyyy format    forums.oracle.com

SharmaAnil wrote: I just need help which i think can never get in this forum. You're wrong. It's that you have it in your own hands. If you have posted an SSCCE, I would without problems have pointed out the error and most probably gave a correct line of code. You seem to think that you're here at a code factory ...

82. Convert String to JPEG Format    forums.oracle.com

Is there a way to codify the previous string to have jpg format? I will readily admit that I know next to nothing about JPEGs, but this just seems like an express trip to insanity. I put this information in a file with extension jpg. However, when I open this file in my operating system, does not recognize it as an ...

83. Help with String Formatting    forums.oracle.com

JavaStudent411 wrote: Thank you, but I can only use the getReal and getImag calls once in this class as required by the instructions. Earlier you posted the instructions as Finally, declare two Normalizable interface variables m1 and m2 that can hold references to two complex numbers. Prompt the user for two complex numbers and create the numbers using these two Normalizable ...

84. Best way to append String (String vs StringBuffer vs String.format    forums.oracle.com

in the small it matters little if you concatenate Strings or use StringBuffer. Now if you are doing thousands of these operations as you read in a file or somesuch, then there may be ramificiations from String object creation. In this situation you're likely better off using a StringBuilder or StringBuffer. I am definitely concatenate a lot of Strings in my ...

85. String formating question    forums.oracle.com

86. String convertion to UTF-8 format    forums.oracle.com

87. Question abotu String.format() functionality    forums.oracle.com

You want the method to treat the strings as multi-line blocks of text instead of as strings? And put the blocks next to each other instead of the strings? Maybe padding the blocks with spaces? Forget it, that's way too complicated for a quick and dirty formatting method. And yes, a whole lot of string manipulation would be going into that. ...

88. String format change (concersion)    forums.oracle.com

Hello friends, I have (any) input string in the format as shown bellow. String input = "(KEY1 a (KEYLOCK1 [G F E D (KEYLOCK2 [C2 C1 C]) B A]))"; I want to convert it in the form shown below: String output = "(KEY1 a (KEYLOCK1 A B (KEYLOCK2 C C1 C2) D E F G))"; Does have any idea can I ...

89. match the string for a particular format    forums.oracle.com

i want to chek the string for a particular format.. lets say for ex , i have to check the string for 6A1N format where A - Alphabets and N - Numbers. that means my string exactly contains 6 alphabets from a to z and one number from 0 to 9 like this i want to check for two more fromats..they ...

90. String replace syntax format    forums.oracle.com

92. Using String.format    forums.oracle.com

93. Converting a string in GregorianCalendar format    forums.oracle.com

Hi I want to convert a string which is exactly in Gregorian Calendar style to GregorianCalendar object so that I can use getTimeInMillis(). Here is the exact situation : Start time = 2008-01-19T00:05:00-06:00 End time = 2008-02-19T00:10:00-06:00 I want the difference in hours. I dont want to do all the split and parsing. Just want to send the two strings and ...

94. Reading a String with dynamic format.    forums.oracle.com

I have 2 questions for you since you mentioned what the real problem is. The first question is how can I join 2 cells that will contain the 2 parts of the nickname in case of a space? Can I just check if the cell number x,y contains "^7" and then just copy that cell the x,y-1? Ive tried that but ...

95. Java Datestamp format question    forums.oracle.com

96. How can get the Date/Time/Number converter for french language format?    forums.oracle.com

For example i send the patterns and language as string in the method. eg. getDate( "JJ/MM/YY","fr",new Date() ) For this type i have to get date as 22/09/07 how can convert the date format into french? For Number format if i pass nuber format like getNumber("0,00","fr", new Double("3.4483")); result should be: 3,45

98. Format String    forums.oracle.com

I am facing two problems. 1. I am getting the output in scientific form for large nos.( as an example, 5.960677545E10), 2.When the number value in a formula cell is containing a rounded-off value the program is returning the actual evaluated value. Suppose, a cell is having the formula =A1*B1 whose actual output should be suppose say, 1.22 but the formula ...

99. format a string in java 1.4    forums.oracle.com

I am facing this problem i have a string amount whose value can be 88.0 , 88.26 but if it is 88.0i want this to be displayed as 88.00 can anyone suggest me how to do this . I know this can be done by String.format but unfortunately I guess this is not available in 1.4 version . any help is ...

100. Simple String.format question    forums.oracle.com

Hi all. I am a newbie in Java and currently I have a problem about String.format function: OK, the code: import java.util.Formatter; public class Foo5 { public static void main(String[] args){ String s = String.format("%,d", 10000); System.out.println(s); } } Simple enough.. but not compile with this error: The method format(String, Object[]) in the type String is not applicable for the arguments ...