How manage String in Java

By Maurizio Farina | Posted on September 2017

How convert Strings to numbers?

A useful summary to convert String to Integer, Long, Float and Double

Type Java Statement
int iNumber = Integer.parseInt(sValue);
long jNumber = Long.parseLong(sValue);
float fNumber = Float.parseFloat(sValue);
double dNumber = Double.parseDouble(sValue);

How to convert a String to a stream?

1
2
byte[] byteArray = Encoding.UTF8.GetBytes(contents);
MemoryStream stream = new MemoryStream(byteArray);

How to convert a stream to String?

1
2
StreamReader reader = new StreamReader(stream);
string text = reader.ReadToEnd();