Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

combine multiple string arrays android

I have two string arrays in my xml file. the code snippet is

<string-array name="ECE1NAME">
    <item>ENG1</item>
    <item>MAT1</item>
    <item>PHY1</item>
    <item>CHM1</item>
    <item>EG</item>
    <item>FOC</item>
    <item>CPL1</item>
    <item>EPL</item>
</string-array>
<string-array name="ECE2NAME">
    <item>ENG2</item>
    <item>CHM2</item>
    <item>PHY2</item>
    <item>MAT2</item>
    <item>ECED</item>
    <item>BCM</item>
    <item>PCL</item>
    <item>CPL2</item>
    <item>CDL</item>
</string-array>

Now I want to combine this into one string depending on the if condition in my class file. My java code snippet is

 if(messagec2.equals("1"))
 {
     sub=getResources().getStringArray(R.array.ECE1NAME);
 }
 if(messagec2.equals("2"))
 {
     sub=getResources().getStringArray(R.array.ECE1NAME);
     sub=getResources().getStringArray(R.array.ECE2NAME);
 }

In the second condition I want to put both the ECE1NAME and ECE2NAME string array into the same variable sub.Please help me.

like image 502
user2980244 Avatar asked Apr 17 '26 00:04

user2980244


1 Answers

take stirng variables like string a[],string B[] and concatenate them like this by passing your values to this method..

private String[] concat(String[] A, String[] B) {
   int aLen = A.length;
   int bLen = B.length;
   String[] C= new String[aLen+bLen];
   System.arraycopy(A, 0, C, 0, aLen);
   System.arraycopy(B, 0, C, aLen, bLen);
   return C;
}
like image 178
kalyan pvs Avatar answered Apr 18 '26 13:04

kalyan pvs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!