开发者

equivalent of arraylist in android

开发者 https://www.devze.com 2023-03-15 03:18 出处:网络
I have the following json format : \"Student id\" \"Name\" \"Semester\" I want to store this information in a listView or any other data structure in android. where i want to associate t开发者_运维知

I have the following json format :

"Student id" "Name" "Semester"

I want to store this information in a listView or any other data structure in android. where i want to associate t开发者_运维知识库he id with name and semester

Is there anything which will be useful for me?

I am a newbie with android code snippets will be helpful.

Thanks, Bhavya


There is ArrayList but you can't store all three elements pointing to each other. What you could do is create a class called Student and add Students to your list. Here's a quick example:

public class Student{
   private long id;
   private String name;
   private int semester;

   //add more methods here
}

List<Student> listOfStudents = new ArrayList<Student>

To parse your JSON, you could use the google-gson library from here.

Ryan


Well, since it's Java there's ArrayList.


You can use hasmap for that

class Student {
    long id;
    String name;
    int semester;
}

Parse JSON and make a objects of Student class and make a Map like this

Hasmap<String,String> arrStudents = new Hasmap<String, String>();
arrStudent.put("id",studentObject);


You can use something like this:

class Student {
    long id;
    String name;
    int semester;
}

to store single person and ArrayList

ArrayList<Student> studentList;

to store more of them

0

精彩评论

暂无评论...
验证码 换一张
取 消