Not being able to access the value of a List

时间:2015-05-04 19:29:02

标签: java list

Problem: This is the result set of my query, which is stored as a List<String>.

1 A ZZZ

2 BB YY

3 CCC X

I know about get(0) and get(1) and so on. But, I am wondering how could I access the 3rd value of each row. Say for example, from the list above I need to access YY, how would I go about doing it?

EDIT: The question was badly presented. Here is a detailed version:

I am running a SQL query - select id, company, department from table_matrix and I get the above mentioned result.

In java, I have written the following code to store the result of the query:

List<String> = the above sql query

Now I need to access the value of CCC, and only CCC. In the above table, I need the value of row 3, column 2. How can I do it if I am using List<String>? If that is not possible, how else may I proceed?

Thanks for the previous comments, and future as well.

2 个答案:

答案 0 :(得分:0)

I am assuming it is a List<String>. In this case you can do this for the row:

String[] strArray = list.get(1).split(" ");
String third = strArray[2];

Of course there are faster ways, but this gets the job done.

答案 1 :(得分:0)

Result set has get method you can use it getInt, getString and it work on the index but it is 1 based index

相关问题