Float to string in java

Java convert float to string using Float.toString() method package com.w3schools; public class FloatToString { public static void main(String args[]){ try { float var = -5.24f; String str = Float.toString(var); System.out.println(“String is: “+str); } catch (Exception e) { e.printStackTrace(); } } } Output: String is: -5.24 Download this example. Java convert float to string using String.valueOf() … Read more

Ascii to string in java

Java convert ascii to string java example package com.w3schools; public class ASCIIToString { public static void main(String args[]){ try { int num[] = {66, 118, 98, 75}; String str =null; for(int i: num){ str = Character.toString((char)i); System.out.println(str); } } catch (Exception e) { e.printStackTrace(); } } } Output: B v b K Download this example.

Date to string in java

Java convert date to string java example package com.w3schools; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class DateToString { public static void main(String args[]){ try { DateFormat df = new SimpleDateFormat(“dd-MMM-yyyy”); String dateString = df.format(new Date()); System.out.println(“Date: ” + dateString); } catch (Exception e) { e.printStackTrace(); } } } Output: Date: 18-Mar-2018 Download this example.

String to date in java

Java convert string to date java example package com.w3schools; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class StringToDate { public static void main(String args[]){ try { String dateString = “18-Mar-2018”; DateFormat df = new SimpleDateFormat(“dd-MMM-yyyy”); Date date = df.parse(dateString); System.out.println(“Date: ” + date); } catch (ParseException e) { e.printStackTrace(); } } } Output: … Read more

Char array to string in java

Java convert char array to string using String constructor. package com.w3schools; public class CharArrayToString { public static void main(String args[]){ char[] ch = {‘J’, ‘a’, ‘i’}; String str = new String(ch); System.out.println(str); } } Output: Jai Download this example. Java convert char array to string using String.valueOf() method package com.w3schools; public class CharArrayToString { public … Read more

String to char in java

Java convert string to char using charAt() method   package com.w3schools; public class StringToChar { public static void main(String args[]){ String str = “w3schools”; for(int i=0; i<str.length();i++){ //Retrieve char from string char ch = str.charAt(i); System.out.println(“Character at “+i+” Position: “+ch); } } } Output: Character at 0 Position: w Character at 1 Position: 3 Character … Read more

Char to string in java

Java convert char to string using Character.toString() method package com.w3schools; public class CharToString { public static void main(String args[]){ char ch = ‘a’; //Convert char to string String str = Character.toString(ch); System.out.println(“String is: “+str); } } Output: String is: a Download this example. Java convert char to string using String.valueOf() method package com.w3schools; public class … Read more

Boolean to string in java

Java convert boolean to string using String.valueOf() method package com.w3schools; public class BooleanToString { public static void main(String args[]){ boolean var = true; //convert boolean to string String str = String.valueOf(var); System.out.println(“String is: “+str); } } Output: String is: true Download this example. Java convert boolean to string using Boolean.toString() method package com.w3schools; public class … Read more

String to boolean in java

Java convert string to boolean using Boolean.parseBoolean() method package com.w3schools; public class StringToBoolean { public static void main(String args[]){ String str1 = “false”; String str2 = “true”; //convert string to boolean boolean var1 = Boolean.parseBoolean(str1); boolean var2 = Boolean.parseBoolean(str2); System.out.println(“Boolean value of str1 is: “+var1); System.out.println(“Boolean value of str2 is: “+var2); } } Output: Boolean … Read more

Long to string in java

Java convert long to string using Long.toString() method package com.w3schools; public class LongToString { public static void main(String args[]){ long var = 765123; //convert long to string String str = Long.toString(var); System.out.println(“String is: “+str); } } Output: String is: 765123 Download this example. Java convert long to string using String.valueOf() method package com.w3schools; public class … Read more