0
In an array of string
I have two words. How will i access the individual letters of those two words.
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/
+ 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...
+ 1
var string ="hello world ";
You can access h of hello world
as :-
var target = string[0] ;
console.log(target);
//h
+ 1
Oh my bad sorry all.
I actually get it as js.