I am trying to get a program working which does the following:
Let's say we have a String
called name
, set to "Stack Overflow Exchange"
. I want to output to the user "SOE"
, with the first characters of each word. I tried with the split()
method, but I failed to do it.
My code:
public class q4 {
public static void main(String args[]) {
String x = "michele jones";
String[] myName = x.split("");
for(int i = 0; i < myName.length; i++) {
if(myName[i] == "") {
String s = myName[i];
System.out.println(s);
}
}
}
}
I am trying to detect if there are any spaces, then I can simply take the next index. Could anyone tell me what I am doing wrong?