string to biginteger java code example
Example 1: transformer un string en Biginteger java
package org.arpit.java2blog;
import java.math.BigInteger;
public class StringToBigIntegerMain {
public static void main(String[] args) {
String str="45";
BigInteger bigIntegerStr=new BigInteger(str);
System.out.println("Converted String to BigInteger: "+bigIntegerStr);
}
}
Example 2: java int to biginteger
int myInt = 10
BigInteger bigInt = BigInteger.valueOf(myInt);
Integer integer = Integer.valueOf(myInt);
BigInteger bigInt = BigInteger.valueOf(myInteger.intValue());
bigInt = BigInteger.valueOf(myInteger);
Example 3: transformer un string en Biginteger java
String foo = "some text";
byte[] fooBytes = foo.getBytes();
BigInteger bi = new BigInteger(fooBytes);
Example 4: transformer un string en Biginteger java
package com.mkyong;
import java.math.BigInteger;
public class JavaExample {
public static void main(String[] args) {
int n = 100;
System.out.println(n);
Integer integer = Integer.valueOf(n);
System.out.println(integer);
BigInteger bigInteger = BigInteger.valueOf(n);
System.out.println(bigInteger);
BigInteger bigInteger2 = BigInteger.valueOf(integer.intValue());
System.out.println(bigInteger2);
}
}
Example 5: transformer un string en Biginteger java
foo = new String(bi.toByteArray());