android arraylist string,Convert ArrayList to String array in Android

I have a ArrayList that contains values in the form [ann,john]. I want to convert this ArrayList into a String array in the form {"ann","john"}.

How should I do this?

My Android code:

final Button markabsent = (Button) findViewById(R.id.Button02);

markabsent.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

// Perform action on click

Toast.makeText(display.this,"You have marked the students absent",Toast.LENGTH_SHORT).show();

SparseBooleanArray checkedabsent = lView.getCheckedItemPositions();

for (int i = 0; i < arr2.length; i++)

{

if (checkedabsent.get(i))

{

items2.add(arr2[i]);

System.out.println(items2);

}

}

Log.d("", "items:");

for (String string : items2)

{

Log.d("string is", string);

}

}

});

My Logcat:

11-10 21:44:00.414: INFO/System.out(2316): [ann, john, ann]

11-10 21:44:00.414: DEBUG/(2316): items:

11-10 21:44:00.414: DEBUG/string is(2316): ann

11-10 21:44:00.414: DEBUG/string is(2316): john

I tried doing everything mentioned in the answers but my logcat just doesn't seem to imrove

Here is the one giving exceptions:

11-10 22:14:20.855: INFO/System.out(3322): [Ljava.lang.String;@44eb6ff0

11-10 22:16:38.186: ERROR/AndroidRuntime(3411): FATAL EXCEPTION: main

11-10 22:16:38.186: ERROR/AndroidRuntime(3411): java.lang.ClassCastException: [Ljava.lang.Object;

11-10 22:16:38.186: ERROR/AndroidRuntime(3411): at com.example.display$2.onClick(display.java:124)

11-10 22:16:38.186: ERROR/AndroidRuntime(3411): at android.view.View.performClick(View.java:2408)

11-10 22:16:38.186: ERROR/AndroidRuntime(3411): at android.view.View$PerformClick.run(View.java:8816)

11-10 22:16:38.186: ERROR/AndroidRuntime(3411): at android.os.Handler.handleCallback(Handler.java:587)

Here is one more:

11-10 22:14:20.875: DEBUG/string is(3322): ann

11-10 22:14:20.875: INFO/System.out(3322): [Ljava.lang.String;@44eb7720

11-10 22:14:20.875: INFO/System.out(3322): [Ljava.lang.String;@44eb7720

11-10 22:14:20.885: INFO/System.out(3322): [Ljava.lang.String;@44eb7720

11-10 22:14:20.895: DEBUG/string is(3322): john

11-10 22:14:20.895: INFO/System.out(3322): [Ljava.lang.String;@44eb7de8

11-10 22:16:38.186: ERROR/AndroidRuntime(3411): at com.example.display$2.onClick(display.java:124)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值