简体   繁体   中英

convert char to string in loop in java and then Set it to JtextField

public void auto() {  
    String x = jTextField1.getText().toUpperCase();  
    String[] myName = x.split(" ");  
    for (int i = 0; i < myName.length; i++) {  
        String s = myName[i];  
        System.out.print(s.charAt(0));  
    }   
}

I just want to get all the first letter of every word and save it to another Text Field how to do it.

Please help me to solve this problem.

Your code already extracts the first letter of each word. For the rest of you question it's quite simple. Put the letters into a variable and set the text of a different textfield.

public void auto() {  
    String result = "";
    String x = jTextField1.getText().toUpperCase();  
    String[] myName = x.split(" ");  
    for (int i = 0; i < myName.length; i++) {  
        String s = myName[i];
        result += s.charAt(0);
    }
    jDifferentTextField.setText(result);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM