How to take individual letters in someone input? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to take individual letters in someone input?

For example when sb input is "dave" then i want each one of member of the word. Can i access each individual letters later. Help me plz

8th Feb 2021, 1:06 PM
Dawit Teshager(Seek Boy)
Dawit Teshager(Seek Boy) - avatar
2 Answers
+ 4
I found this thread for you: https://stackoverflow.com/questions/2451650/how-do-i-apply-the-for-each-loop-to-every-character-in-a-string#2451660 String str = "xyz"; for(int i = 0; i < str.length(); i++){ char c = str.charAt(i); } or String str = "xyz"; char arr[] = str.toCharArray();
8th Feb 2021, 1:16 PM
Apollo-Roboto
Apollo-Roboto - avatar
+ 1
Better with Streams adopting Functional Programming. Why?? With arrays you are limited to int size. Streams there are not this limitation, so you can process huge texts even fork in little tasks to process in parallel. https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/stream/Stream.html A hint how to start... https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/regex/Pattern.html#splitAsStream(java.lang.CharSequence) Stream<String> charStream = Pattern.compile("").splitAsStream("your text"); The magic is made by providing an empty string to Pattern. It splits by chars
9th Feb 2021, 7:48 PM
David Ordás
David Ordás - avatar