Java, How do i use add a string and an integer to an array -


this array code have far:

arraylist<data> arrl = new arraylist<data>();     arrl.add("tim", 23);     

need know how integer , string array.

for example:

names: , ages: tim 23 max 56 clare 43

i know how add integers or strings array-lists can't figure how incorporate both in same array.

your list taking objects of type data. so, create data class contains string name , int age. create data object each entry want , add arrl list.

public class data {      private string name;     private int age;       /**      * constructor      */     public data(string name, int age) {         this.name = name;         this.age = age;     }      // getters , setters go here. } 

in example used constructor allow easy construction of data object name , age.

list<data> arrl = new arraylist<data>(); arrl.add(new data("tim", 23));  

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -