This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Is it possible to get Arraylist from String.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have just pasted my code over here.Can anyone of you find the solution for obtaining the Array list from the String.

For Example :

ArrayList al = new ArrayList();
al.add(new byte[2]);
al.add("2");

String stringVar = "" + (ArrayList) al;

Here I can convert the arraylist into string.But can we do he vice versa like obtaining the above arraylist from the string?If please advice me.

URGENT!!!
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you want to put the String into the ArrayList? Character by Character? Is the String formatted in a similar fashion to what gets returned by the toString method in AbstractCollection, which is inherited by ArrayList?
 
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rahul reddy:
Hi all,

I have just pasted my code over here.Can anyone of you find the solution for obtaining the Array list from the String.

For Example :

ArrayList al = new ArrayList();
al.add(new byte[2]);
al.add("2");

String stringVar = "" + (ArrayList) al;

Here I can convert the arraylist into string.But can we do he vice versa like obtaining the above arraylist from the string?If please advice me.

URGENT!!!



You can use StringTokenizer to parse or tokenize a string and add it to an ArrayList. I believe StringTokenizer has some deficiencies in that it can't handle "100 North Main Street, #110", New York, NY - that is, a delimiter in the data. But you do get to choose your delimiter.

This example builds an ArrayList, converts it to a string, and puts it back into another array list. NOTE: because I created the string from ArrayList.toString() I had to add extra logic to remove the [] that ArrayList adds when converting to a String.


[ August 07, 2007: Message edited by: Red Smith ]
reply
    Bookmark Topic Watch Topic
  • New Topic