Daviyow Posted March 31, 2014 Share Posted March 31, 2014 (edited) Hey, my head just exploded. How can i pass this into a string for GroundItem? ex: GroundItem lewt = ("Huge turd", "Flashlight"); public static ArrayList<String> GUILoot = new ArrayList<String>(); My arraylist outprints this atm: [iNFO ][04/01/14 01:21:22 AM]: GUILoot: [Vial, Herb, Bones] thanks! Edited March 31, 2014 by daviyow Link to comment Share on other sites More sharing options...
Swizzbeat Posted March 31, 2014 Share Posted March 31, 2014 GUILoot.toArray(new String[GUILoot.size()]); Link to comment Share on other sites More sharing options...
Daviyow Posted March 31, 2014 Author Share Posted March 31, 2014 GUILoot.toArray(new String[GUILoot.size()]); If i try to log it, it says GUILoot: [Ljava.lang.String;@32f50bf4 log("GUILoot: "+GUILoot.toArray(new String[GUILoot.size()])); ? Link to comment Share on other sites More sharing options...
Swizzbeat Posted March 31, 2014 Share Posted March 31, 2014 If i try to log it, it says GUILoot: [Ljava.lang.String;@32f50bf4 log("GUILoot: "+GUILoot.toArray(new String[GUILoot.size()])); ? Oh whoops, I misunderstood your original post just iterate through them. Link to comment Share on other sites More sharing options...
Daviyow Posted March 31, 2014 Author Share Posted March 31, 2014 Oh whoops, I misunderstood your original post just iterate through them. can i do that in my getState? cus i have some checks for loot in my state or where would be the past part to do this Link to comment Share on other sites More sharing options...
Swizzbeat Posted April 1, 2014 Share Posted April 1, 2014 can i do that in my getState? cus i have some checks for loot in my state or where would be the past part to do this Wherever you think would be best. Forgot an ArrayList returned the string with brackets though, so you can just pass them in easy and replace the characters you don't want. GUILoot.toString().replace("[", "").replace("]", ""); Link to comment Share on other sites More sharing options...
Fay Posted April 1, 2014 Share Posted April 1, 2014 for(String loot : GUILoot){ loot.replace("[","").replace("]",""); } Link to comment Share on other sites More sharing options...
ProbsNotAssumeTb Posted April 1, 2014 Share Posted April 1, 2014 Wherever you think would be best. Forgot an ArrayList returned the string with brackets though, so you can just pass them in easy and replace the characters you don't want. GUILoot.toString().replace("[", "").replace("]", ""); eww why #replace twice? ewwwww String#replaceAll("[\\]\\[]", "") Link to comment Share on other sites More sharing options...
Fay Posted April 1, 2014 Share Posted April 1, 2014 eww why #replace twice? ewwwww String#replaceAll("[\\]\\[]", "") bringing suggestions not solutions. Link to comment Share on other sites More sharing options...
Pandemic Posted April 1, 2014 Share Posted April 1, 2014 bringing suggestions not solutions. That was the solution >.< Link to comment Share on other sites More sharing options...
Bjergsen Posted April 1, 2014 Share Posted April 1, 2014 1. Iterate (Foreach) 2. Remove the [ and ] Link to comment Share on other sites More sharing options...
Ande Posted April 1, 2014 Share Posted April 1, 2014 (edited) public boolean lootOnGround(){ GroundItem g; for (String s: GUILoot){ g = closestGroundItemForName(s); if(g != null) return true; } return false; } Or just closestGroundItemForName((String[])GUILoot.toArray()) to pass it as a whole Edited April 1, 2014 by Ande Link to comment Share on other sites More sharing options...
PolishCivil Posted April 1, 2014 Share Posted April 1, 2014 String[] array = {"s","n","d"}; String s = Arrays.toString(array); System.out.println(s.replaceAll(", ","\",\"").replace("[","(").replace("]",")").replace("(","(\"").replace(")","\");")); } Idk it works but it should Link to comment Share on other sites More sharing options...
PolishCivil Posted April 1, 2014 Share Posted April 1, 2014 String[] array = {"s","n","d"}; String s = Arrays.toString(array); System.out.println(s.replaceAll(", ","\",\"").replace("[","(").replace("]",")").replace("(","(\"").replace(")","\");")); } Idk it works but it should Link to comment Share on other sites More sharing options...
Daviyow Posted April 1, 2014 Author Share Posted April 1, 2014 Wherever you think would be best. Forgot an ArrayList returned the string with brackets though, so you can just pass them in easy and replace the characters you don't want. GUILoot.toString().replace("[", "").replace("]", ""); Is that ok to place this under dispose(); at GUI? Link to comment Share on other sites More sharing options...