6 Answers
New AnswerString input = "Hallo"; for (int i = 0; i < input.length(); i++) { if (input.charAt(i) == 'a') { // Do stuff if reach char a }
String s = "hello"; //use .charAt() char c = s.charAt(3); //l //loop from 0 to length - 1 for(int i = 0; i < s.lengt(); i++){ System.out.println(s.charAt(i)); } You can also get a char array from the string: char[] letter = s.toCharArray();
Look also here for other string methods: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html
Awesome. Thanks guys I was really getting fed up cause I couldn't do a thing with strings other than printing them 😅 I also think that would be the problem with a lot of other beginners learning on solo learn because none of it is found on the lessons.
Presenting all methods would go beyond the scope of the courses. It is important that you learn to use java documentation in addition to SL. Here are a few other Java resources: https://www.sololearn.com/discuss/580291/?ref=app
Not all methods but just a few like this one and also datatype conversion would also be good. Thanks for the references, appreciate it.