tostring

toString Override in Java

三世轮回 提交于 2019-12-20 04:24:26
问题 This question is from an assignment. I have to override a toString() method in a class that creates a circularly linked list and I actually have a toString() method that works great, it passes all of my tests everything. So my project is autograded and it apparently doesn't approve of my method 100%. So my question is: is there a better way to write this toString() method that would be more efficient? public String toString() { if (size == 0) { return "[]"; } else { String output = ""; Node<E

What is the meaning of the information that I get by printing an Object in Java? [duplicate]

孤街醉人 提交于 2019-12-20 03:07:22
问题 This question already has answers here : How do I print my Java object without getting “SomeType@2f92e0f4”? (10 answers) Closed 2 years ago . Lets say i have this code : Integer[] a= new Integer[5]; System.Out.println(((Object)a).toString()); the output is get is [Integer@89fbe3 what is the meaning of 89fbe3 ? is this some kind of address ? hash code? is it unique for each object? , and if so- if its a multi-threaded program , is it still unique ? thanks ! 回答1: It's the memory address of the

How can I determine if an object can ToString into value or type name?

…衆ロ難τιáo~ 提交于 2019-12-19 21:29:21
问题 I am writing an interop between a php service and our crm. One of the things I need to do is make sure that simple types get converted ToString() for use later in a json converter. I am not sure even what the name is for 'simple types' but it can be defined like this... "an object that represents a low level variable type, containing a single value, not a class or anything with executable functions etc" I've found that int, string, bool, double, and surprisingly enum will ToString() with

How to “echo” a class?

谁说胖子不能爱 提交于 2019-12-19 12:49:57
问题 This is probably really easy but I can't seem to figure out how to print/echo a class so I can find out some details about it. I know this doesn't work, but this is what I'm trying to do: <?php echo $class; ?> What is the correct way to achieve something like this? 回答1: If you just want to print the contents of the class for debugging purposes, use print_r or var_dump. 回答2: You could try adding a toString method to your class. You can then echo some useful information, or call a render method

c# Decimal to string for currency

走远了吗. 提交于 2019-12-19 05:07:06
问题 To display a currency we do: ToString("0.##") For value 5.00 the output is: 5 For value 5.98 the output is: 5.98 For value 5.90 the output is: 5.9 I need the third case to come out with 2 decimal points, eg: 5.90 How can I do this without it affecting the other results? 回答1: I know this doesn't give you a format that fixes the problem, but it's a simple solution to work around it. (5.00).ToString("0.00").Replace(".00",""); // returns 5 (5.90).ToString("0.00").Replace(".00", ""); // returns 5

Read Registry_binary and convert to string

限于喜欢 提交于 2019-12-19 04:07:53
问题 I have been searching for the last 2 hours, and I actualy just have been searching stupid. I am trying to read a Registry_binary Value and convert this to a string. I tried several things I've found online(includeing some stackoverflow posts), but seems I cannot get it work: class Class1 { RegistryKey RegKey; String keys; static void Main() { Class1 c=new Class1(); c.initialize(); } void initialize() { RegKey=Registry.LocalMachine.OpenSubKey("the location", true); var bytearray=Converter

C# int ToString format on 2 char int?

醉酒当歌 提交于 2019-12-18 18:39:24
问题 How do I use the ToString method on an integer to display a 2-char int i = 1; i.ToString() -> "01" instead of "1" Thanks. 回答1: You can use i.ToString("D2") or i.ToString("00") See Standard Numeric Format Strings and Custom Numeric Format Strings on Microsoft Docs for more details 回答2: This should do it: String.Format("{0:00}",i); Here's a link to an msdn article on using custom formatting strings: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx 回答3: In order to ensure at least 2 digits

C# int ToString format on 2 char int?

若如初见. 提交于 2019-12-18 18:37:18
问题 How do I use the ToString method on an integer to display a 2-char int i = 1; i.ToString() -> "01" instead of "1" Thanks. 回答1: You can use i.ToString("D2") or i.ToString("00") See Standard Numeric Format Strings and Custom Numeric Format Strings on Microsoft Docs for more details 回答2: This should do it: String.Format("{0:00}",i); Here's a link to an msdn article on using custom formatting strings: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx 回答3: In order to ensure at least 2 digits

Join an array by a comma and a space

青春壹個敷衍的年華 提交于 2019-12-18 18:33:51
问题 I have an array that I want converted to a comma delimited string. Array.toString() works, but if I have a rather large array it won't wrap because there are no spaces after the commas: document.body.innerHTML = ['css','html','xhtml','html5','css3','javascript','jquery','lesscss','arrays','wordpress','facebook','fbml','table','.htaccess','php','c','.net','c#','java'].toString(); // css,html,xhtml,html5,css3,javascript,jquery,lesscss,arrays,wordpress,facebook,fbml,table,.htaccess,php,c,.net,c#

How to get floats value without including exponential notation

∥☆過路亽.° 提交于 2019-12-18 14:55:35
问题 In C#, is it possible to perform ToString on a float and get the value without using exponentials? For example, consider the following: float dummy; dummy = 0.000006F; Console.WriteLine(dummy.ToString()); This gives the output 6E-06 However, what I was is 0.000006 The closest I could find was using the "F" qualifier, however I then need to specify the number of decimal places otherwise the value get rounded. Is there actually a way of doing this automatically or do I need to do a load of