String[] array = (String[])vector.toArray();

Why does the last line cause a ClassCastException?:
Vector vector = new Vector();
vector.add("One");
vector.add("Two");
vector.add("Three");
vector.add("Four");
vector.add("Five");
String[] array = (String[])vector.toArray();
Thanks
[email protected]

Because toArray () creates an Object array. You need the toArray(Object[]):String[] array = (String[]) vector.toArray (new String[vector.size ()]);Kind regards,
  Levi

Similar Messages

  • Flex input type for c# string array: string[]

    Quick question, what would the input type for Flex be if the data type on the asp.net c# web service was a string array, string[], it seems to autodetect it as an ArrayCollection but that isnt right, so I would assume array, but i would still like to confirm this.
    thanks
    shaine

    it was actually arraycollection :\
    the actual answer is:
    var _compEmp:ArrayCollection = new ArrayCollection(new Array("Shaine Fisher"));
    thanks

  • Converting String Array -- String

    Hi All,
    I am converting String array to string using the following code:
    String[] a= ....;
    StringBuffer result = new StringBuffer();
    if (a.length > 0) {
    result.append(a[0]);
    for (int i=1; i<a.length; i++) {
    result.append(a);
    return result.toString();
    Is there is any other easy or efficient way to convert rather than the above code ?
    Thanks,
    J.Kathir

    It could have been written:
    StringBuffer result = new StringBuffer();
    for(int i=0; i<a.length; ++ i)
        result.append(a);
    return result.toString();
    Or in 1.5 lingo
    StringBuilder result = new StringBuilder(); //slightly less overhead
    for(String s : a)
        result.append(s);
    return result.toString();If you aren't picky about the format of the resulting string,
    you could use the java.utilArrays method )]toString(Object[]):
    String[] array= {"Hello", "World", "this", "is", "a", "1.5", "method"};
    String s = Arrays.toString(array); //[Hello, World, this, is, a, 1.5, method]

  • Converting vector to string array

    How can I convert values in a vector into a string array?
    Vector formsVector = new Vector();
    while (rs.next())
    {formsVector.add(rs.getString("forms"));}
    String forms[] = (String[])formsVector.toArray();
    I tried the above line but it did not work. Any input please?
    Thanks

    .... What is the difference between the two as
    according to online help, both are same.
    String forms[] = (String [])formsVector.toArray();
    String forms[] = (String [])formsVector.toArray( new
    String[0] );The difference lies in the type of the object returned from toArray. The first form you list, formsVector.toArray(), always returns an Object[]. In your example, you'll get a ClassCastException at runtime when you cast to String[].
    The second form will try to use the array you pass in. If it's not big enough, it'll create a new one of the same type as that array. This is what's happening when passing a zero-length array into toArray.
    My personal preference is to save an extra instantiation and build the array to the proper size to begin with:String forms[] = (String [])formsVector.toArray( new String[formsVector.size()] );

  • Return String array in server side

    i wrote a bean which contains a function return String array (
    String[] ). It shows no error on compile time, and also in
    generate jar file. However, when i generate it to an ear file,
    the syntax of the wsdl file is not correct so the client can't
    call this function becuase the xml can't parse the wsdl.
    When i change the return type to String, everything is ok. Does
    anybody know what's happen? I really have no idea on it, thx.

    This is why I wanted to see some code. I wanted to see how you are trying to move the array from one class to another.
    This should work... provided that the array is initialised correctly in ClassA. If you are doing it like this, please post some code and I'll help you fix it.
    class ClassA{
    public String[] getMyArray(){
    return myArray;
    class ClassB{
    public void myMethod(){
    ClassA myA = new ClassA();
    String[] newArray = myA.getMyArray();
    }

  • Adding to a string array

    hi,
    seem to be having some trouble adding to a string array of names
    im trying to take a name from a text field and add it to the array
    help would be much appreciated
    this is the string array
    String[] AuthorString =     {"John Grisham","Agatha Christie","Nick Coleman","Scott Sinclair"};which is loaded into
    public void fillArrayList(){
         for(int a=0; a<AuthorString.length; a++) {
         AuthorList.add((String)AuthorString[a]);
                         }i then try and add to this using
    public void AddMember(){
         String temp = (String)AuthorField.getSelectedItem();
         for(int a=0; a>AuthorList.size(); a++) {
         String temp = (String)AuhtorList.get(a);
              AuthorString .addItem(temp);
          }can anyone see any problem with this, or am i doing it the completely wrong way

    Also, your "for" loop's test condition is backwards. It should use "less than":
    a < AuthorList.size()

  • How to use Multimaps (Map String, ArrayList String )

    I was using an array to store player names, userIDs, uniqueIDs, and frag counts, but after reading about multimaps in the tutorials, it seems that would be much more efficient. However, I guess I don't quite understand it. Here's how I wanted things stored in my string array:
    String[] connectedUsers = {"user1_name", "user1_userid", "user1_uniqueid", "user1_frags"
                                            "user2_name"...}and here is how I'm attempting to setup and use the 'multimap':
    public class Main {
        static Map<String, ArrayList<String>> connectedUsers;
        public void updatePlayers(String name, String status) {
            String[] statusSplit = status.split(" ");
            if (connectedUsers.containsKey(name)) {
                connectedUsers.put(name, statusSplit[0]);
            else {
                connectedUsers.put(name, statusSplit[0]);
        }It's quite obvious I don't understand how this works, but should I even set this multimap up this way? Perhaps I should use a regular map with a string array for the values?

    You're cool MrOldie. Its just that alarm bells start ringing in my head when people come on and post as much as you do.
    * Created on Jul 28, 2005 by @author Tom Jacobs
    package tjacobs;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.Map;
    import java.util.Set;
    import java.util.TreeSet;
    * ManyMap is a map that allows more than one value to be stored with any key
    * <p>
    * There are a number of methods in the class that have been deprecated because
    * the original functionality of Map has been violated to accomodate the concept
    * of the ManyMap
    public class ManyMap<T, T2> implements Map<T, T2> {
         private HashMap<T, ArrayList<T2>> mInnerMap;
         public ManyMap() {
              mInnerMap = new HashMap<T, ArrayList<T2>>();
          * @deprecated
         public T2 get(Object obj) {
              ArrayList<T2> ar = _get(obj);
              if (ar == null || ar.size() == 0) {
                   return null;
              return ar.get(0);
         public Iterator<T2> getAll(Object obj) {
              ArrayList<T2> ar = _get(obj);
              if (ar == null || ar.size() == 0) {
                   return null;
              return ar.iterator();          
         public T2 put(T obj1, T2 obj2) {
              ArrayList<T2> ar = _getNotNull(obj1);
              ar.add(obj2);
              return obj2;
         public Set<Map.Entry<T, T2>> entrySet() {
              TreeSet<Map.Entry<T, T2>> entries = new TreeSet<Map.Entry<T, T2>>();
              Iterator<T> _i = mInnerMap.keySet().iterator();
              while (_i.hasNext()) {
                   T key = _i.next();
                   Iterator<T2> vals = mInnerMap.get(key).iterator();
                   while (vals.hasNext()) {
                        Entry<T, T2> entry = new Entry<T, T2>(key, vals.next());
                        entries.add(entry);
              return entries;
         public int size() {
              return mInnerMap.size();
         public int valuesSize() {
              int vals = 0;
              Iterator<T> _i = mInnerMap.keySet().iterator();
              while (_i.hasNext()) {
                   T key = _i.next();
                   ArrayList<T2> ar = mInnerMap.get(key);
                   vals += ar.size();
              return vals;
         public void clear() {
              mInnerMap.clear();
         public void putAll(Map<? extends T, ? extends T2> map) {
              Iterator _i = map.entrySet().iterator();
              while(_i.hasNext()) {
                   Map.Entry<? extends T, ? extends T2> entry = (Map.Entry<? extends T, ? extends T2>) _i.next();
                   put(entry.getKey(), entry.getValue());
         public Collection <T2> values() {
              LinkedList ll = new LinkedList();
              Iterator<ArrayList<T2>> _i = mInnerMap.values().iterator();
              while (_i.hasNext()) {
                   ll.addAll(_i.next());
              return ll;
         public boolean containsValue(Object val) {
              Iterator<ArrayList<T2>> values = mInnerMap.values().iterator();
              while (values.hasNext()) {
                   if (values.next().contains(val)) return true;
              return false;
         public boolean containsKey(Object key) {
              return mInnerMap.containsKey(key);
         public T2 remove(Object obj) {
              Iterator<ArrayList<T2>> values = mInnerMap.values().iterator();
              boolean found = false;
              while (values.hasNext()) {
                   if (values.next().remove(obj)) {
                        found = true;
              return found ? (T2)obj : null;
         public boolean isEmpty() {
              return valuesSize() == 0;
         @SuppressWarnings("hiding")
         private class Entry<T, T2> implements Map.Entry<T, T2> {
              T key;
              T2 val;
              public Entry (T obj1, T2 obj2) {
                   key = obj1;
                   val = obj2;
              public T2 getValue() {
                   return val;
              public T getKey() {
                   return key;
              public T2 setValue(T2 obj) {
                   return val = obj;
         public Set<T> keySet() {
              return mInnerMap.keySet();
         public ArrayList<T2> _get (Object obj) {
              return mInnerMap.get(obj);
         public ArrayList<T2> _getNotNull (T obj) {
              ArrayList<T2> list = _get(obj);
              if (list == null) {
                   list = new ArrayList<T2>(1);
                   mInnerMap.put(obj, list);
              return list;
    }Edited by: tjacobs01 on Aug 19, 2008 12:28 PM

  • Vector to String Array

    Hello all...
    How can i convert a vector to a string array?

    If it's inserted into the vector as a String, then the toArray() method is exactly what you want. Otherwise, a simple for loop doing a "array[i] = thing.toString()" bit ought to do nicely.

  • WHY WE USE VECTOR NOT ARRAY STRING

    Hi
    I want to know why we use Vector not bufferstring.
    What is the difference Vector(1,1) and STRING[1][1]?
    Which one we will prefer?
    Why we will prefer one of them?
    Please help me to find out.

    There are huge differences between array and Vector.
    Array is a special class that allows to keep references to a number of Objects of some type. It has a maximum length set during construction, and does not offer any methods to change it's size (without defining a new array).
    Vector is a class (thread-safe unlike it's new version ArrayList) that allows to keep references to any Object (may be of different types). It doesn't have a maximum length set, and can be potentionally of any size. It allows to easily remove, add, insert new elements and keeps all the elements in the order they were added (unless some object was inserted). This is a really well written class, and I'm always using it for storing some objects.
    Hope it was helpful.

  • SET into string array using toArray()

    I have a object java.util.Set collection and I want to convert all the elements
    into a string array but i don't know why it is not working in my JSP page...
    as i am trying to use toArray() method
    i have tried this          
    String[]  arr = collection.toArray();this
    String[]  arr = (String []) collection.toArray();could you please tell me the right way to aplly it...
    thanks in advance....:)

    I am using session listener which map sessions and it stores sessionid which i hope is a string
    when i directly print this set object it shows
    [ED0EF456BD1EE956A069340633C8DB87,UT0EF456BD1EE956A069340633C8DB34,RD0EF456BD1EE956A069340633C8DB98]
    Message was edited by:
    hunterzz

  • Cast Object Array to String Array.

    When I try to cast an object array to string array an exception is thrown. How do I go about doing it?
    Vector temp = new Vector();
    Object[] array = temp.toArray();
    String[] nonterms;                              
    nonterms = (String[])array;
    Thanks,
    Ally

    Try this
    import java.util.Vector;
    public class Test
         public static void main(String args[]) throws Exception
              Vector v = new Vector();
              v.add("a");
              v.add("b");
              v.add("c");
              Object[] terms = v.toArray();
              for(int i = 0; i < terms.length; i++)
                   System.out.println((String)terms);
    Raghu

  • New user with an  massive array/string headache

    Working with a large (365 source files, 65 mxml files) SDK 3.6.0 project in FB 4.5 and continually get :
    Resource
    Path
    Location
    Description
    Type
    TB4.mxml
    /the0bot_1/src/the0bot/gui
    line 1
    1067: Implicit coercion of a value of type String to an unrelated type Array.
    Flex Problem
    TB4.mxml
    /the0bot_1/src/the0bot/gui
    line 1
    1184: Incompatible default value of type String where Array is expected.
    Flex Problem
    It is a very strange error, as you can see, line #1 is my language declaration!
    <?xml version="1.0" encoding="utf-8"?>
    This error is virtually non-removable.  It usually attaches to a component, or an ArrayCollection, and even if I delete the accused violator, the error will find a new point of attachment.?  This is the only page in the project that involves two-way data binding.  I had at first attributed the error to a yahoo.astra.com timestepper drop-in, but even rebuilding the page without that component does not remedy the trouble....
    Any help at this point would be appreciated, There are countless hours invested in the project and this has been a hold-up for several days now. 
    Thank you.

    Nothing had changed project-wise originally. I am simply adding a new mxml component to a perfectly good runnable project. I have since moved my workspace twice to a clean folder, and if  I remove the module everything is back to normal.
    I do notice that it won't show up if I have a normal error (i.e add a visual component but have not added code yet or forget a brace or such) but then when I clear the last error and validate, the cursor will jump to the top of the page mmediately.
    currently the errors are
    Resource
    Path
    Location
    Description
    Type
    TB4.mxml
    /the0bot_1/src/the0bot/gui
    line 296
    1067: Implicit coercion of a value of type String to an unrelated type Array.
    Flex Problem
    TB4.mxml
    /the0bot_1/src/the0bot/gui
    line 296
    1184: Incompatible default value of type String where Array is expected.
    Flex Problem
    (they have moved off the header to the reinstalled numberformatter)
    the code:
    Some may seem a little unconventional, but I have been getting strange errors like 
    Resource
    Path
    Location
    Description
    Type
    TB4.mxml
    /the0bot_1/src/the0bot/gui
    line 222
    1105: Target of assignment must be a reference value.
    Flex Problem
    which is why the 2 " tbean(t) = n; " lines are commented out.     ( tbean = object, t = string, n = number)???
    (all the bindings are an attempt at elimination....)
    <?xml version="1.0" encoding="utf-8"?>
         <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
                             xmlns:gui="the0bot.gui.*"
                             width="418" height="289">
              <mx:Script>
                        <![CDATA[
                                  import com.evony.common.beans.*;
                                  import com.evony.common.constants.*;
                                  import com.google.analytics.debug._Style;
                                  import flash.events.*;
                                  import flash.utils.*;
                                  import mx.collections.ArrayCollection;
                                  import mx.controls.Button;
                                  import mx.events.*;
                                  import mx.events.ItemClickEvent;
                                  import mx.events.PropertyChangeEvent;
                                  import mx.utils.ObjectUtil;
                                  import the0bot.common.*;
                                  import the0bot.event.CityManagerUpdateEvent;
                                  import the0bot.management.*;
                                  import the0bot.management.CityManager;
                                  import the0bot.player.*;
                                  import the0bot.scripts.*;
                                  private var cityManager:CityManager;
                                  private var city:CityState;
                                  public var _THE0BOT:String = "the0bot";
                                  public var the0bot:Boolean;
                                  public static const yes:Boolean = true;
                                  public static const no:Boolean = false;
                                  public static const zero:int = 0;
                                  public static const resource:Array = ("food", "wood", "stone", "iron", "gold");
                                  [Bindable]public var text:String;
                                  [Bindable]public var value:Number;
                                  [Bindable]public var tb2Heroes:ArrayCollection;
                                  [Bindable]public var tb2Troops:ArrayCollection;
                                  [Bindable]public var tb3Queue:ArrayCollection;
                                  [Bindable]public var tb2Resources:ArrayCollection;
                                  [Bindable]public var tb2Cities:ArrayCollection;
                                  [Bindable]public var selectedIndex:int;
                                  [Bindable]public var selectedCity:String;
                                  [Bindable]public var selectedHero:String;
                                  [Bindable]public var selectedtb3:String;
                                  // Rom
                                  public function init(citymanager:CityManager,City:CityState) : void {
                                            cityManager = citymanager;
                                            city=City;
                                            the0bot = (this.cityManager.getConfig(_THE0BOT, 0));
                                            resettb2Data();
                                            listCities;
                                            cityManager.addEventListener(CityManagerUpdateEvent.TYPE, onUpdate);
                                            Context.getInstance().addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, onContexthandler);
                                            Context.getInstance().addEventListener(CityManagerUpdateEvent.TYPE, onUpdate);
                                            Refresh();
                                  public function unInit() : void {
                                            if (cityManager.hasEventListener(CityManagerUpdateEvent.TYPE))
                                                      cityManager.removeEventListener(CityManagerUpdateEvent.TYPE, onUpdate);
                                            if (Context.getInstance().hasEventListener(CityManagerUpdateEvent.TYPE))
                                                      Context.getInstance().removeEventListener(CityManagerUpdateEvent.TYPE, onUpdate);
                                            cityManager = null;
      public function Refresh() : void {
                                            this.callLater(updateHeroes);
                                  [Bindable]private var travelTime:Number;
                                  [Bindable]private var campTime:Number;
                                  private function onContexthandler(event:PropertyChangeEvent) : void
                                            campTime = (Number(campMinutes.text)* 60000) + campSeconds.value * 1000;
                                            var t =(Utils.getServerTime() + travelTime + campTime)as Date;
                                            _arriveClock.text = TFseconds.format(t);
                                            (xSpin.value >= 800)? xSpin.value=0 : (xSpin.value <= -1)? xSpin.value = 799 :t=null;
                                            (ySpin.value >= 800)? ySpin.value=0 : (ySpin.value <= -1)? ySpin.value = 799 :t=null;
                                  private function onUpdate(event:CityManagerUpdateEvent) : void {
                                            if (event.CastleId == cityManager.id || event.CastleId == -1) {
                                                      switch (event.UpdateType) {
                                                                case CityManagerUpdateEvent.TROOPS:
                                                                case CityManagerUpdateEvent.PRODUCTION:
                                                                          Refresh();
                                                                          break;
                                  private function updateHeroes():void
                                            if (heroMenu.selectedIndex != zero) return;
                                            tb2Heroes.disableAutoUpdate();
                                            tb2Heroes = new ArrayCollection;
                                            for each (var hero:HeroBean in cityManager.heroes){
                                                      if (hero.isIdle == yes){
                                                                var obj:Object = new Object;
                                                                obj.label = hero.name;
                                                                tb2Heroes.addItem(obj);
                                            obj = {label:"any"};
                                            tb2Heroes.addItemAt(obj, 0);
                                            obj = {label:"none"};
                                            tb2Heroes.addItemAt(obj, 0);
                                            tb2Heroes.enableAutoUpdate();
                                            heroMenu.selectedIndex = zero;
                                  public function resettb2Troops() : void
                                            var tb2:Array = new Array();
                                            for (var t:int = 0; t < TroopType.justTroopIntNames.length-1; t++ )
                                                      tb2[t].label = TroopType.justTroopAbbr[t];
                                                      tb2[t].data = 0;
                                                      tb2[t].type = TroopType.justTroopIntNames[t];
                                            tb2Troops = new ArrayCollection(tb2);
                                  private function resettb2Resources():void
                                            var tb2:Array = new Array;
                                            for (var i:int = 0; i < resource.length-1; i++);
                                                      tb2.label = resource[i].charAt(0) + ":";
                                                      tb2.data = 0;
                                                      tb2.type = resource[i];
                                            tb2Resources = new ArrayCollection(tb2);
                                  private function listCities():void{
                                            tb2Cities = new ArrayCollection;
                                            for each (var gcity:CityState in Context.getInstance().cities){
                                                      var obj:Object = new Object;
                                                      obj.label = gcity.cityManager.castle.name;
                                                      obj.id = gcity.cityManager.castle.fieldId;
                                                      (obj.id == this.cityManager.castle.fieldId) ? tb2Cities.addItemAt(obj, zero) : tb2Cities.addItem(obj);
                                  private function resettb2Data():void
                                            resettb2Troops()
                                            resettb2Resources()
                                            updateHeroes();
                                            listCities();
                                  public function doesHaveEnsign(): Boolean {
                                            var player:* = Context.getInstance().Player;
                                            for each (var item:* in player.itemsArray) {
                                                      if (item.id == null) continue;
                                                      if (item.id == "player.troop.1.a") return true;
                                            return false;
                                  protected function campSwitchClick(event:MouseEvent):void
                                            /* if (campSwitch.selected = yes) arriveSwitch.selected = no;
                                            else {campMinutes.text = "0";
                                                      campSeconds.value=0;
                                  protected function arriveSwitchClick(event:MouseEvent):void
                                            if (arriveSwitch.selected = yes){
                                                      campSwitch.selected = no;
                                                      travelTime=0;
                                            else travelTime = getArmyMarchTime();
                                  public function tb2troopsToBean():TroopBean{
                                            var tbean = new TroopBean;
                                            var tb2:Array = tb2Troops.toArray()
                                            for (var i:int = 0; i < tb2.length-1; i++ )
                                            var n:Number = tb2[i].data;
                                            var t:String = tb2[i].type;
                                            //tbean(t) = n;
                                            return tbean;
                                  public function tb2resToBean():ResourceBean{
                                            var tbean = new ResourceBean;
                                            var tb2:Array = tb2Resources.toArray();
                                            for (var i:int = 0; i < tb2.length-1; i++ )
                                                      var n:Number = tb2[i].data;
                                                      var t:String = tb2[i].type;
                                                      //tbean(t) = n;
                                            return tbean;
                                  private  function spinCoordsString():String
                                            return xSpin.value + "," + ySpin.value;
                                  private  function missionTypeIndex():int
                                            var s:int=marchMenu.selectedIndex+1;
                                            if (s==4)s++;
                                            return s;
                                  private  function spinnersToFieldID():int{
                                            return (int(ySpin.value)*800 + int(xSpin.value));
                                  private  function fieldIDtoSpinners(fieldID:int):void
                                            xSpin.value = Map.getX(fieldID);
                                            ySpin.value = Map.getY(fieldID);
                                  public function getArmyMarchTime():Number{
                                            return cityManager.getAttackTravelTime(this.cityManager.id, spinnersToFieldID(), tb2troopsToBean(), missionTypeIndex());
                                  protected function xySpin_changeHandler():void
                                  protected function sendSwitchClick(event:MouseEvent):void
                                            var t:TroopBean = tb2troopsToBean();
                                            var r:ResourceBean = tb2resToBean();
                                            var camp:String = "";
                                            var time:String = campMinutes.text + ":" + campSeconds.textSnapshot;
                                            camp += (arriveSwitch.selected) ? "@:" + time : (campSwitch.selected) ? "c:" + time : "";
                                            if (!useEnsignSwitch.selected == yes)
                                                      this.city.sendTroops(spinCoordsString(), TroopType.troopBeanToString(t,","), missionTypeIndex(), heroMenu.text, r, camp);
                                            else this.city.sendBigTroops(spinCoordsString(), TroopType.troopBeanToString(t,","), missionTypeIndex(), heroMenu.text, r, camp);
                                            heroMenu.selectedIndex = zero;
                                            updateHeroes();
                                  protected function citycloseHandler(event:FlexEvent):void
                                            for each (var gcity:CityState in Context.getInstance().cities){
                                                      if (gcity.cityManager.castle.name == cityMenu.selectedLabel){
                                                                fieldIDtoSpinners(gcity.cityManager.castle.fieldId);
                                  private function herocloseHandler(event:Event):void {
                                            selectedHero = ComboBox(event.target).selectedItem.label;
                        ]]>
              </mx:Script>
              <mx:DateFormatter id="TFseconds" formatString="J:NN:SS"/>
              <mx:HBox width="415" height="288" horizontalGap="5" horizontalScrollPolicy="off" paddingTop="5"
                                   verticalScrollPolicy="off">
                        <mx:VBox width="277" height="280" horizontalAlign="center" horizontalScrollPolicy="off"
                                             verticalGap="4" verticalScrollPolicy="off">
                                  <mx:HBox x="0" y="0" height="276" horizontalGap="5" paddingLeft="5" paddingTop="3">
                                            <mx:VBox height="267" horizontalScrollPolicy="off" paddingTop="5" verticalGap="4"
                                                                 verticalScrollPolicy="off">
                                                      <mx:HBox id="troopCountBox" width="125" height="25" borderColor="#2B1296"
                                                                           borderStyle="solid" borderThickness="2" cornerRadius="5"
                                                                           horizontalAlign="center" horizontalGap="0" horizontalScrollPolicy="off"
                                                                           verticalScrollPolicy="off">
                                                                <mx:Label width="37" paddingTop="2" text="Army" textAlign="center"/>
                                                                <mx:Text width="70" paddingTop="2" text="125,000" textAlign="left"/>
                                                      </mx:HBox>
                                                      <mx:DataGrid id="table1" width="125" height="226" backgroundAlpha=".1"
                                                                                     backgroundColor="#EADFF2" borderColor="#400AAF" borderStyle="solid"
                                                                                     borderThickness="2" dataProvider="{tb2Troops}"
                                                                                     lockedColumnCount="2" lockedRowCount="12"
                                                                                     resizableColumns="false" rowHeight="20" selectionMode="singleCell"
                                                                                     showHeaders="false" sortableColumns="false"
                                                                                     variableRowHeight="false">
                                                                <mx:columns>
                                                                          <mx:DataGridColumn width="35" dataField="abbr" editable="false"
                                                                                                                      fontSize="10"/>
                                                                          <mx:DataGridColumn width="90" dataField="data" editable="true"
                                                                                                                      editorDataField="value" fontSize="10"
                                                                                                                      formatter="{nf}"
                                                                                                                      itemEditor="mx.controls.NumericStepper"/>
                                                                </mx:columns>
                                                      </mx:DataGrid>
                                            </mx:VBox>
                                            <mx:VBox width="131" height="268" horizontalAlign="center" paddingTop="5" verticalGap="4">
                                                      <mx:HBox width="125" height="25" borderColor="#2B1296" borderStyle="solid"
                                                                           borderThickness="2" cornerRadius="5" horizontalAlign="center" horizontalGap="0"
                                                                           horizontalScrollPolicy="off" verticalScrollPolicy="off">
                                                                <mx:Label width="31" paddingLeft="0" paddingRight="0" paddingTop="2" text="Res."
                                                                                      textAlign="right"/>
                                                                <mx:Text width="80" paddingTop="2" text="999,999,999" textAlign="left"/>
                                                      </mx:HBox>
                                                      <mx:DataGrid id="table2" width="125" height="139" allowMultipleSelection="false"
                                                                                     backgroundAlpha=".1" backgroundColor="#DBE4F5" borderColor="#400AAF"
                                                                                     dataProvider="{tb2Resources}" lockedColumnCount="2" lockedRowCount="5"
                                                                                     resizableColumns="false" rowHeight="20" selectionMode="singleCell"
                                                                                     showHeaders="false" sortableColumns="false" variableRowHeight="false">
                                                                <mx:columns>
                                                                          <mx:DataGridColumn width="35" dataField="abbr" editable="false"
                                                                                                                      fontSize="10" headerText="Type" textAlign="right"/>
                                                                          <mx:DataGridColumn dataField="data" editable="true"
                                                                                                                      editorDataField="value" fontSize="10" formatter="nf"
                                                                                                                      headerText="Amt." textAlign="right">
                                                                                    <mx:itemEditor>
                                                                                              <mx:Component>
                                                                                                         <mx:NumericStepper doubleClickEnabled="true"
                                                                                                                                                    maximum="{resMax()}"
                                                                                                                                                    stepSize="1"/>
                                                                                              </mx:Component>
                                                                                    </mx:itemEditor>
                                                                          </mx:DataGridColumn>
                                                                </mx:columns>
                                                      </mx:DataGrid>
                                                      <mx:HBox horizontalScrollPolicy="off" verticalAlign="middle"
                                                                           verticalScrollPolicy="off">
                                                                <mx:Label width="33" height="19" text="Arr:" textAlign="right"/>
                                                                <mx:Text id="_arriveClock" width="76" height="21" paddingLeft="2" paddingTop="1"
                                                                                     text="00:00:00" textAlign="left"/>
                                                      </mx:HBox>
                                                      <mx:HBox width="84" horizontalGap="0" horizontalScrollPolicy="off" verticalScrollPolicy="off">
                                                                <mx:TextInput id="campMinutes" width="23" fontWeight="bold" maxChars="3"
                                                                                                 restrict="0-9" text="00" textAlign="right"/>
                                                                <mx:Text width="7" fontWeight="bold" selectable="false" text=":"
                                                                                     textAlign="right"/>
                                                                <mx:NumericStepper id="campSeconds" width="49" fontWeight="bold" maximum="59" value="" textAlign="left"/>
                                                      </mx:HBox>
                                                      <mx:ComboBox id="marchMenu" width="100" editable="false" fillColors="black,blue"
                                                                                     textAlign="center">
                                                                <mx:dataProvider>
                                                                          <mx:Array>
                                                                                    <mx:String>transport</mx:String>
                                                                                    <mx:String>reinforce</mx:String>
                                                                                    <mx:String>scout</mx:String>
                                                                                    <mx:String>attack</mx:String>
                                                                          </mx:Array>
                                                                </mx:dataProvider>
                                                      </mx:ComboBox>
                                            </mx:VBox>
                                  </mx:HBox>
                        </mx:VBox>
                        <mx:HBox width="125" height="280" borderColor="#400AAF" borderStyle="solid"
                                             borderThickness="2" cornerRadius="5" horizontalGap="3" horizontalScrollPolicy="off"
                                             paddingLeft="4" paddingTop="4" verticalScrollPolicy="off">
                                  <mx:VBox width="115" height="269" horizontalAlign="center" horizontalScrollPolicy="off"
                                                       verticalGap="5" verticalScrollPolicy="off">
                                            <mx:RadioButton id="useEnsignSwitch" width="65" label="Ensign"/>
                                            <mx:HBox width="100%" height="27" borderColor="#3F2AC1" borderStyle="solid"
                                                                 borderThickness="2" cornerRadius="5" horizontalAlign="center"
                                                                 verticalAlign="middle">
                                                      <mx:Button id="editSwitch" width="45" height="20" label="Edit" enabled="false"
                                                                             paddingLeft="1" paddingRight="1" toggle="true"/>
                                                      <mx:Button id="FMJSwitch" width="45" height="20" label="F.M.J."
                                                                             click="campSwitchClick(event)" enabled="false" paddingLeft="1"
                                                                             paddingRight="1" selected="true" toggle="true"/>
                                            </mx:HBox>
                                            <mx:ComboBox id="tb3Menu" width="100" dataProvider="{tb2Heroes}" editable="false"
                                                                           close="tb3closeHandler(event)" fillColors="black,blue" selectedIndex="0"
                                                                           textAlign="center">
                                            </mx:ComboBox>
                                            <mx:ComboBox id="cityMenu" width="100" dataProvider="{tb2Cities}" editable="false"
                                                                           close="citycloseHandler(event)" fillColors="black,blue" selectedIndex="0"
                                                                           textAlign="center">
                                            </mx:ComboBox>
                                            <mx:ComboBox id="heroMenu" width="100" dataProvider="{tb2Heroes}" editable="false"
                                                                           close="herocloseHandler(event)" fillColors="black,blue" selectedIndex="0"
                                                                           textAlign="center">
                                            </mx:ComboBox>
                                            <mx:HBox width="100" height="28" horizontalAlign="center" horizontalGap="0" paddingBottom="0"
                                                                 paddingLeft="0" paddingRight="0" paddingTop="0" verticalAlign="middle">
                                                      <mx:Label text="X:"/>
                                                      <mx:NumericStepper id="xSpin" width="55" change="xySpin_changeHandler(event)"
                                                                                                  maximum="800" minimum="-1" value="0"/>
                                            </mx:HBox>
                                            <mx:HBox width="100" height="28" horizontalAlign="center" horizontalGap="0"
                                                                 horizontalScrollPolicy="off" paddingBottom="0" paddingLeft="0" paddingRight="0"
                                                                 paddingTop="0" verticalAlign="middle" verticalScrollPolicy="off">
                                                      <mx:Label text="Y:"/>
                                                      <mx:NumericStepper id="ySpin" width="55" change="xySpin_changeHandler(event)"
                                                                                                  maximum="800" minimum="-1" value="0"/>
                                            </mx:HBox>
                                            <mx:HBox width="108" height="26" borderColor="#3F2AC1" borderStyle="solid"
                                                                 borderThickness="2" cornerRadius="5" horizontalAlign="center"
                                                                 horizontalScrollPolicy="off" verticalAlign="middle" verticalScrollPolicy="off">
                                                      <mx:Button id="sendSwitch" width="45" height="22" label="Send" borderColor="#60C592"
                                                                             click="sendSwitchClick(event)" paddingLeft="1" paddingRight="1"/>
                                                      <mx:Button id="clearSwitch" width="54" height="22" label="Clear"
                                                                             click="clearSwitch_clickHandler(event)"/>
                                            </mx:HBox>
                                            <mx:HBox width="100%" height="27" borderColor="#3F2AC1" borderStyle="solid"
                                                                 borderThickness="2" cornerRadius="5" horizontalAlign="center"
                                                                 verticalAlign="middle">
                                                      <mx:Button id="arriveSwitch" width="45" height="20" label="Arrive" enabled="true"
                                                                             paddingLeft="1" paddingRight="1" toggle="true"/>
                                                      <mx:Button id="campSwitch" width="45" height="20" label="Camp"
                                                                             click="campSwitchClick(event)" enabled="true" paddingLeft="1"
                                                                             paddingRight="1" selected="true" toggle="true"/>
                                            </mx:HBox>
                                  </mx:VBox>
                        </mx:HBox>
              </mx:HBox>
    </mx:Canvas>

  • Array of String Arrays

    How do I make an array of String Arrays, not knowing how big the array will be
    or how big any of the arrays it contains will be at the time I create it?

    The size of an array is not dynamic, i.e. if you use an array, you must know its size at the time you create it.
    Use one of the collection classes (like java.util.Vector or one of the implementation classes of java.util.List).
    regards
    Jesper

  • Get String array from Resultset

    In Tomcat 6.0.20 I am attempting to create an Oracle 9i resultset that outputs as a String array and need help creating the method.
    The CityData getCityList() method will be called in the CityServlet:
    CityServlet: String [] citys = cityData.getCityList();
    I started my below attempt but not sure how to handle the List/array part:
    CityData class: public ArrayList<String> getCityList() {     try {           .....           List<String> citys = new ArrayList<String>();           while(rs.next())           {               citys.add(rs.getString("city"));           }       }     return citys; }

    Hi!
    Try this:
    public City[] getCitys() throws Exception
        String sql = "SELECT * FROM citys ORDER BY name ASC";
        Vector v = new Vector();       
        ResultSet rs = null;
        java.sql.Statement stmt = null;
        try
            stmt = conn.createStatement();
            rs = stmt.executeQuery(sql);
            while( rs.next() )
                City city = new City(rs);
                v.add(city);
        catch (Exception e) { throw e; }
        finally
            try
                if (stmt != null) stmt.close();
            catch (Exception e) { throw e; }
        City[] citys = new City[v.size()];
        for (int i = 0; i < citys.length; i++)
            citys[i] = (City)v.get(i);
        return citys;       
    }Edited by: Bejglee on Mar 3, 2010 3:59 AM

  • How to convert String array into int.

    void getSoldSms(Vector vecSoldSms)
         String str[]=new String[vecSoldSms.size()];
         String words[]=new String[str.length]; // String array
              for(int i=0;i< vecSoldSms.size();i++)
                   str=(String)vecSoldSms.get(i);
              }               //End for
              for(int i=0;i<str.length;i++)
              words = str[i].split("\\|\\|");
              System.out.println();
              for(int j=0;j<1;j++)     
              int count[str.length]=Integer.parseInt(words[i]);
              System.out.print(count[j]*advance_count);
              } // end inner for loop
              }          //End for
         }          //End function getSoldSms
    how do i convert words which is a string array into int type. i kno string can be converted into int using interger.parseint. but wat abt string arrays??? plz help me out with the above code.

    i did tht its still giving the same errorFor Heaven's sake, what about taking a second to try to understand the code you're copying first? If you really can't fix the error yourself, you have a more serious problem than just convertingStrings to ints.
    And if you want { "1", "2", "3" } to be 123:
    StringBuffer b = new StringBuffer();
    for (int i = 0; i < array.length; i++) {
      b.append(array);
    int result = Integer.parseIn(b.toString());

Maybe you are looking for