1

I have a DepositTypes class with CharSequence array as a parameter. I used setter and getter for CharSequence depositPeriod[]. In generatePeriod() I have to generate some random numbers and save them to depositPeriod[] for each item of the DepositTypes class.

In my MainActitvity class I need to retrieve depositPeriod by final CharSequence charSequence[] = deposit_types.get(positionOfDeposit).getDepositPeriod();. When I check the value of charSequence I got [Ljava.lang.CharSequence;@bd8aa05

Question How to get a CharSequence from DepositTypes class and use it in MainActivity

class DepositTypes {
    ...
    private CharSequence depositPeriod[];

private DepositTypes(..., ...,  CharSequence depositPeriod[]) {
    ...
    setDepositPeriod(depositPeriod);
}
   ... ...

public CharSequence[] getDepositPeriod() {
    return depositPeriod;
}

public void setDepositPeriod(CharSequence[] depositPeriod) {
    this.depositPeriod = depositPeriod;
}

static List<DepositTypes> generateDepositTypes(Context context) {
    ArrayList<DepositTypes> deposits = new ArrayList<>();
     ...
     ...

    Random rand = new Random();


    for (int i = -1; i < deposit_types.length; i++) {
        if (i != -1) {
           CharSequence[] depositPeriod = generatePeriod();     
           deposits.add(new DepositTypes(..., ..., depositPeriod));
        } else {
            ...
            ...
        }
    }
    return deposits;
}
static CharSequence[] generatePeriod() {
    Random rand = new Random();
    int period = rand.nextInt(3) + 3;
    CharSequence[] depositPeriod = new String[period];

    for (int i = 0; i < period; i++) {
        int days = rand.nextInt(335) + 31;
        depositPeriod[i] = String.valueOf(days);
        Log.v("AAA", "in Class -> " + depositPeriod[i]);
    }

    return depositPeriod;
}

}

Abdugani_T
  • 83
  • 1
  • 11

1 Answers1

0

CharSequense is an interface, you need to use the toString() method to access the underlying string value

CharSequence[] charSequence = deposit_types.get(positionOfDeposit).getDepositPeriod();
for(sequence CharSequence : charSequence) {
   String string = sequence.toString()
   //... do stuff with string
}
Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52