Java Technology - 2018 - Conversion
package com.practice.conversionpractice;
public class ConversionPractice {
public static void main(String[] args) {
boolean boolean1 = true;
byte byte1 = 12;
char char1 = 'a';
short short1 = 13;
int int1 = 14;
long long1 = 15;
float float1 = 1.23f;
double double1 = 2.34;
String str = "Apple";
// =============================
// String to int when String is Integer
System.out.println(Integer.parseInt("233")); // 233
// or
System.out.println(Integer.valueOf("323")); // 323
// ------------------------------
// int to String
System.out.println(99 + String.valueOf(int1)); // 9914
// or
System.out.println(99 + Integer.toString(int1)); // 9914
// or
String s1 = String.format("%d", int1);
System.out.println(99 + s1);// 9914
System.out.println(99 + int1);// 113 Because int1 is int
// ======================
// ===================================
// String to Long when String is Long
System.out.println("%%%%%%%%%%%%%%%%%");
System.out.println(Long.parseLong("323")); // 233
// or
System.out.println(Long.valueOf("323")); // 323
// long to String
System.out.println(99 + String.valueOf(long1)); // 9915
// or
System.out.println(99 + Long.toString(long1)); // 9915
// or
String s2 = String.format("%d", long1);
System.out.println(99 + s2);// 9915
System.out.println(99 + long1);// 114
// ======================
}
}
public class ConversionPractice {
public static void main(String[] args) {
boolean boolean1 = true;
byte byte1 = 12;
char char1 = 'a';
short short1 = 13;
int int1 = 14;
long long1 = 15;
float float1 = 1.23f;
double double1 = 2.34;
String str = "Apple";
// =============================
// String to int when String is Integer
System.out.println(Integer.parseInt("233")); // 233
// or
System.out.println(Integer.valueOf("323")); // 323
// ------------------------------
// int to String
System.out.println(99 + String.valueOf(int1)); // 9914
// or
System.out.println(99 + Integer.toString(int1)); // 9914
// or
String s1 = String.format("%d", int1);
System.out.println(99 + s1);// 9914
System.out.println(99 + int1);// 113 Because int1 is int
// ======================
// ===================================
// String to Long when String is Long
System.out.println("%%%%%%%%%%%%%%%%%");
System.out.println(Long.parseLong("323")); // 233
// or
System.out.println(Long.valueOf("323")); // 323
// long to String
System.out.println(99 + String.valueOf(long1)); // 9915
// or
System.out.println(99 + Long.toString(long1)); // 9915
// or
String s2 = String.format("%d", long1);
System.out.println(99 + s2);// 9915
System.out.println(99 + long1);// 114
// ======================
}
}
Comments
Post a Comment