Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-06-2007, 08:02 AM
Member
 
Join Date: Dec 2007
Posts: 1
mars123 is on a distinguished road
Arraylist to a 2- dimension array conversion
I have an arraylist which needs to be converted to a two dimenional array.

Eg:

Arraylist contains:
------------------
abc
def
ghi
jkl

Resultant Array should contain elements in the below fashion:
-----------------------
(abc,def)
(ghi,jkl)

Thanks in advance.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-06-2007, 12:24 PM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Code:
ArrayList<String> ar = new ArrayList<String>(); ar.add("abc"); ar.add("def"); ar.add("ghi"); ar.add("jkl"); // error handling, if the array size of not even. if (ar.size() % 2 != 0) { System.out.println("ArrayList cannot have odd number of values if to be converted to String[][]"); return; } String[][] ray = new String[ar.size()/2][2]; int c = 0; for (int i = 0; i < ar.size(); i = i+2) { ray[c][0] = ar.get(i); ray[c][1] = ar.get(i+1); c++; }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Project Trouble: Searching one ArrayList with another ArrayList BC2210 New To Java 2 04-21-2008 12:43 PM
String to Integer conversion eva New To Java 2 12-17-2007 04:59 PM
Converting ArrayList to Array Java Tip Java Tips 0 11-13-2007 11:41 AM
Array to ArrayList javaplus New To Java 2 11-12-2007 01:46 AM
Problem in TIFF Conversion lakshmipriyam Advanced Java 1 08-09-2007 11:44 PM


All times are GMT +3. The time now is 03:47 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org