JPad
Snippets
Download
Help
Contact
converting_array_to_map_in_Java
Code
// Converting int to String and Strings to int // Integer to numeric string String numericString = String.valueOf(2); // Numeric string to an int int integer = Integer.parseInt(numericString); Dump(numericString, "Numeric String"); Dump(integer, "Int"); // Converting String to date in Java String myStringDate = "21.09.2018"; SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy" ); Date date = format.parse( myStringDate ); Dump(date, "Date"); // Converting Java util.Date to sql.Date SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "dd/MM/yyyy" ); Date utilDate = simpleDateFormat.parse("21/09/2018"); java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); Dump(utilDate, "Util Date"); Dump(sqlDate, "SQL Date"); // Get name of current method String methodName = Thread.currentThread().getStackTrace()[1].getMethodName(); Dump(methodName, "Current Method Name");
Result
Console
Numeric String => 2 Int => 2 Date => 2018-09-21T00:00:00.000 Util Date => 2018-09-21T00:00:00.000 SQL Date => 2018-09-21 Current Method Name => main
Bytecode
Compiled from "RunnContainer.java" public class io.jpad.scratch.RunnContainer { public io.jpad.scratch.RunnContainer(); Code: 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String...) throws java.lang.Exception; Code: 0: iconst_2 1: invokestatic #2 // Method java/lang/String.valueOf:(I)Ljava/lang/String; 4: astore_1 5: aload_1 6: invokestatic #3 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I 9: istore_2 10: aload_1 11: ldc #4 // String Numeric String 13: invokestatic #5 // Method io/jpad/scratch/Dumper.Dump:(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object; 16: pop 17: iload_2 18: invokestatic #6 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; 21: ldc #7 // String Int 23: invokestatic #5 // Method io/jpad/scratch/Dumper.Dump:(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object; 26: pop 27: ldc #8 // String 21.09.2018 29: astore_3 30: new #9 // class java/text/SimpleDateFormat 33: dup 34: ldc #10 // String dd.MM.yyyy 36: invokespecial #11 // Method java/text/SimpleDateFormat."<init>":(Ljava/lang/String;)V 39: astore 4 41: aload 4 43: aload_3 44: invokevirtual #12 // Method java/text/SimpleDateFormat.parse:(Ljava/lang/String;)Ljava/util/Date; 47: astore 5 49: aload 5 51: ldc #13 // String Date 53: invokestatic #5 // Method io/jpad/scratch/Dumper.Dump:(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object; 56: pop 57: new #9 // class java/text/SimpleDateFormat 60: dup 61: ldc #14 // String dd/MM/yyyy 63: invokespecial #11 // Method java/text/SimpleDateFormat."<init>":(Ljava/lang/String;)V 66: astore 6 68: aload 6 70: ldc #15 // String 21/09/2018 72: invokevirtual #12 // Method java/text/SimpleDateFormat.parse:(Ljava/lang/String;)Ljava/util/Date; 75: astore 7 77: new #16 // class java/sql/Date 80: dup 81: aload 7 83: invokevirtual #17 // Method java/util/Date.getTime:()J 86: invokespecial #18 // Method java/sql/Date."<init>":(J)V 89: astore 8 91: aload 7 93: ldc #19 // String Util Date 95: invokestatic #5 // Method io/jpad/scratch/Dumper.Dump:(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object; 98: pop 99: aload 8 101: ldc #20 // String SQL Date 103: invokestatic #5 // Method io/jpad/scratch/Dumper.Dump:(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object; 106: pop 107: invokestatic #21 // Method java/lang/Thread.currentThread:()Ljava/lang/Thread; 110: invokevirtual #22 // Method java/lang/Thread.getStackTrace:()[Ljava/lang/StackTraceElement; 113: iconst_1 114: aaload 115: invokevirtual #23 // Method java/lang/StackTraceElement.getMethodName:()Ljava/lang/String; 118: astore 9 120: aload 9 122: ldc #24 // String Current Method Name 124: invokestatic #5 // Method io/jpad/scratch/Dumper.Dump:(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object; 127: pop 128: return }
Jpad Version:1.07
viewCount:2038
Creator:
marcelocomp
Latest Editor:
marcelocomp
Tags
Download
Copy As Markdown:
**code [converting_array_to_map_in_Java.java](/example/1L/converting-array-to-map-in-java)** // Converting int to String and Strings to int // Integer to numeric string String numericString = String.valueOf(2); // Numeric string to an int int integer = Integer.parseInt(numericString); Dump(numericString, "Numeric String"); Dump(integer, "Int"); // Converting String to date in Java String myStringDate = "21.09.2018"; SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy" ); Date date = format.parse( myStringDate ); Dump(date, "Date"); // Converting Java util.Date to sql.Date SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "dd/MM/yyyy" ); Date utilDate = simpleDateFormat.parse("21/09/2018"); java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); Dump(utilDate, "Util Date"); Dump(sqlDate, "SQL Date"); // Get name of current method String methodName = Thread.currentThread().getStackTrace()[1].getMethodName(); Dump(methodName, "Current Method Name"); **Result:** Numeric String => 2 Int => 2 Date => 2018-09-21T00:00:00.000 Util Date => 2018-09-21T00:00:00.000 SQL Date => 2018-09-21 Current Method Name => main