Jump to content

navdeep

Members
  • Posts

    2
  • Joined

  • Last visited

About navdeep

  • Birthday 01/03/1991

Profile Information

  • Location
    Indore, MP, India
  • College Major/Degree
    SGSITS Indore/BE in CSE
  • Favorite Area of Science
    Computer Science

navdeep's Achievements

Lepton

Lepton (1/13)

0

Reputation

  1. thanks 'Greg H.' for the prompt reply.. my problem is solved now.. but i figured one more way of iterating through the array list, thought i would share with you, it goes as follows: import java.util.*; class al { public static void main(String nav[]) { String[] st1={"One"}; String[] st2={"One", "Two"}; String[] st3={"One", "Two", "Three"}; String[] st4={"One", "Two", "Three", "Four"}; String[] st5={"One", "Two", "Three", "Four", "Six"}; ArrayList obj=new ArrayList(); obj.addAll(Arrays.asList(st1, st2, st3, st4, st5)); for(int i=0; i<obj.size(); i++) System.out.println(Arrays.toString((String[]) obj.get(i))); } } Output- [One] [One, Two] [One, Two, Three] [One, Two, Three, Four] [One, Two, Three, Four, Six] thanking you again..
  2. consider- String[] str1={"One"}; String[] str2={"One","Two"}; String[] str3={"One","Two", "Three"}; String[] str4={"One","Two", "Three", "Four"}; String[] str5={"One","Two", "Three", "Four","Five"}; ArrayList al=new ArrayList(); al.add(str1); al.add(str2); al.add(str3); al.add(str4); al.add(str5); till now i have successfully added 5 arrays in the array list, al.. now i want to retrieve each element of each array.. if i use iterator- Iterator itr=al.iterator(); while(itr.hasNext()) { System.out.println("Element : "+itr.next()); } i get- Element : [Ljava.lang.String;@182f0db Element : [Ljava.lang.String;@192d342 Element : [Ljava.lang.String;@6b97fd Element : [Ljava.lang.String;@1c78e57 Element : [Ljava.lang.String;@5224ee clearly, these are addresses of those 5 arrays, i dont want them, i want the elements, output should be- One One Two One Two Three One Two Three Four One Two Three Four Five so my question, how to retrieve them? but i guess i can achieve this by using List and probably even achieve my goal but what if i only want the value "Three" from the array str3 that is now in al, how would i retrieve it? desired output- Value at 3rd position of al's 3rd element : Three
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.