-2
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView txt1 = (TextView) findViewById(R.id.txt1);
        TextView txt2 = (TextView) findViewById(R.id.txt2);
        TextView txt3 = (TextView) findViewById(R.id.txt3);
        TextView txt = (TextView) findViewById(R.id.txt4);
        String myStringValue = "Android programming is fun.";
        txt1.setText(myStringValue);
        txt2.setText(myStringValue.charAt(0) + "");
    }

i want to choose more than one character in charAt().

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • No. **charAt** takes one and only one character. But you can still extract a substring out of a string. – Phantômaxx Apr 16 '19 at 08:22
  • No, then it wouldn't return a char. You could try getting a sub string if you wanted multiple characters. What are you trying to achieve exactly? – deadwards Apr 16 '19 at 08:22
  • Possible duplicate of [Extract substring from a string](https://stackoverflow.com/questions/5414657/extract-substring-from-a-string) – Phantômaxx Apr 16 '19 at 08:22

1 Answers1

0

charAt() always return one char. if you want more you must use other method or create loop for you purpose.

For example

    String myStringValue = "Android programming is fun.";
    StringBuilder textViewText = new StringBuilder();
    for(int i = 0 ; i< myStringValue.length();i++){
        if (i>=24 && i<=26){
            textViewText.append(myStringValue.charAt(i));
        }
    }
    Log.i("test",textViewText.toString());//print fun

Or use substring method

txt2.setText(myStringValue.substring(24,26) + "");//print fun
Radesh
  • 13,084
  • 4
  • 51
  • 64