0

Looking to split string to array

I have attached the code and I want to split the string to the new array of strings. I'm trying but I can't do it. Can anyone help? Thank you! https://code.sololearn.com/c8KzoQOH8kNW/?ref=app

9th Feb 2023, 6:19 PM
Sibusiso Mbambo
5 Réponses
+ 1
Your trying to split a string of length 1. It does not effect anything. You will get same string so length 1 only then index 1 is out of range.. Use index 0 instead.
9th Feb 2023, 6:40 PM
Jayakrishna 🇮🇳
+ 1
I don't understanding your question.. Is this you are trying? for(int i = 0; i < alphabet.length; i++) System.out.println(alphabet[i]);
9th Feb 2023, 6:51 PM
Jayakrishna 🇮🇳
+ 1
After split, the result must be at least 2 parts. But string ex: "A" , cannot be split. If you split, it returns the same. May be you trying String of letter A to Z, and split to each character...!? Then try this : public class Program { public static void main(String[] args) { String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String[] strArr = str.split("\\r*"); for(int i = 0; i <strArr.length; i++) System.out.println(strArr[i]); } }
9th Feb 2023, 7:08 PM
Jayakrishna 🇮🇳
0
Jayakrishna 🇮🇳 the printed letters from A to Z to D. I want each letter have it own index.
9th Feb 2023, 6:46 PM
Sibusiso Mbambo
0
The original alphabets from array of string are from A to Z "String[] alphabets". From the resulting string which is printed is from A to Z to D. I want to split and print the resulting string of alphabet as an array. Example. Index[0] is A index[1] is B and so on...
9th Feb 2023, 7:00 PM
Sibusiso Mbambo