0

In an array of string

I have two words. How will i access the individual letters of those two words.

20th Aug 2020, 8:44 AM
stephen haokip
stephen haokip - avatar
4 Answers
+ 5
stephen haokip A String is a sequence of characters or groups of characters. For e.g. “Hello” is a string containing 5 characters that are a sequence of characters ‘h’, ‘e’, ‘l’, ‘l’, and ‘o’. Basically, a string is an array of characters, and each character stored in a specific index. String in java are objects but internally it is an array of characters. Whenever we create a String the JVM automatically creates the array of characters. In java string toCharArray() method is used to convert string to char array. It is the easiest way to convert a java string to char array, the toCharArray() method creates a new character array with the same length as the length of the string. When it creates a new char array, the original string is left unchanged. See the example: https://javagoal.com/string-tochararray/
20th Aug 2020, 2:38 PM
Raina Dhankhar
Raina Dhankhar - avatar
+ 2
stephen haokip String s[] = { "abcd", "cdef" } ; You can use s[0].toCharArray() function. You can use for loop.. for(char ch : s[0]) { ..... } You can use s[0].charAt(index) function...
20th Aug 2020, 11:20 AM
Jayakrishna 🇼🇳
+ 1
var string ="hello world "; You can access h of hello world as :- var target = string[0] ; console.log(target); //h
20th Aug 2020, 8:55 AM
Divya Mohan
Divya Mohan - avatar
+ 1
Oh my bad sorry all. I actually get it as js.
20th Aug 2020, 12:38 PM
Divya Mohan
Divya Mohan - avatar