Answer the question
In order to leave comments, you need to log in
How to fill an array with numbers from a string?
The input is a string with 4 numbers. How to fill an array with numbers from a string?
//строка "11 0 0 17"
byte[] byteArray = new byte[4];
byteArray[0] = //первое из "11 0 0 17"
byteArray[1] = //второе из "11 0 0 17"
byteArray[2] = //третье из "11 0 0 17"
byteArray[3] = //четвертое из "11 0 0 17"
Answer the question
In order to leave comments, you need to log in
String str = "11 0 0 17";
byte[] byteArray = new byte[4];
String[] strArray = str.split(" ");
for (int x = 0; x < strArray.length; x++) {
if (x >= byteArray.length)
break;
byteArray[x] = Byte.parseByte(strArray[x]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question