arraylist

starting index from 1 not from 0

My question is simple ,how can I start the index in an ArrayList from 1 instead of 0 ? is this possible directly (I mean is there a code for this ) ?. Actually a friend asked me this question today, first I thought that it is a silly question but after a while I thought if there is a direct way to do that and decided to ask it to you (m...

how to read an arraylist from a txt file in java?

How to read an arraylist from a txt file in java? My arraylist is of the form: public class Account { String username; String password; } I managed to put some "Accounts" in the a txt file, but now I don't know how to read them. This is how my arraylist looks in the txt file: username1 password1 | username2 password2 | etc ...

Accessing ArrayList in Javascript - ASP.Net MVC2

Hi I have ArrayList in my Model and want to iterate through it in my javascript. I am using following code but its giving me error : CS0103: The name 'i' does not exist in the current context for(var i=0; i <= <%=Model.KeyList.Count%>; i++) { alert('<%=Model.KeyList[i]%>'); } How to get rid of this. its ...

Getting a java collection of objects in Alphabetical order

I have a question that I dont really know where to start. So I thought i'd ask it here. Basically, I have a drop down with names in it. I want these names to be in alphabetical order. Populating the drop down happens as follows; I query a database and pull down an Id and Name, make a object called "UserList", and set the name and id v...

Generating All Permutations of Character Combinations when # of arrays and length of each array are unknown

Hi everyone, I'm not sure how to ask my question in a succinct way, so I'll start with examples and expand from there. I am working with VBA, but I think this problem is non language specific and would only require a bright mind that can provide a pseudo code framework. Thanks in advance for the help! Example: I have 3 Character Arrays ...

Benefits of arrays

As I see it, the advantages of a list over an array are pretty obvious: Generics provide more precise typing: List<Integer>, List<? extends Number>, List<? super Integer>. A List interface has a bunch useful methods: addAll, remove etc. While for arrays all standard operations except get/set must be performed in a procedure manner by p...

Is ArrayList.size() method cached?

I was wondering, is the size() method that you can call on a existing ArrayList<T> cached? Or is it preferable in performance critical code that I just store the size() in a local int? I would expect that it is indeed cached, when you don't add/remove items between calls to size(). Am I right? update I am not talking about inlining ...

Help with abstract class in Java with private variable of type List<E>

Hi, It's been two years since I last coded something in Java so my coding skills are bit rusty. I need to save data (an user profile) in different data structures, ArrayList and LinkedList, and they both come from List. I want to avoid code duplication where I can and I also want to follow good Java practices. For that, I'm trying to ...

How to initialize List<E> in empty class constructor?

Hi, The following code obviously doesn't work because List<E> is abstract: public class MyList { private List<E> list; public MyList() { this.list = new List<E>(); } } How can I initialize MyList class with an empty constructor if I need the list variable to be a LinkedList or a ArrayList depending on my needs? ...

Vector vs Collections.synchronizedList(ArrayList)

Vector is synchronized but ArrayList is not synchronized but we can synchronize an ArrayList by Collections.synchronizedList (aList), so which will perform better and faster ...

When you call remove(object o) on an arraylist, how does it compare objects?

When you call remove(object o) on an arraylist in java, how does it compare the objects to find the correct one to remove? does it use the pointer? or does it compare the objects using the interface Comparable? ...

how to get HashTable values as Arraylist ?

Hi all, I have: Hashtable <String, Word> hw How can I convert its values to: ArrayList <Word> arr thanks. ...

Split Java ArrayList by properties of contained Objects

I have an ArrayList containing Objects that have a date value. Now I want to manage to create a new ArrayList for each year that contains all the Objects from the main ArrayList that have the same year in their date Value. So all Objects from 2010 go in one List, all from 1999 in another. ...

mockito ArrayList<String> problem...

I have a method that I am trying to unit test. This method takes a parameter as an ArrayList and does things with it. The mock I am trying to define is: ArrayList<String> mocked = mock(ArrayList.class); which gives a [unchecked] unchecked conversion" warning. ArrayList<String> mocked = mock(ArrayList<String>.class); gives me an...

using Object input\ output Streams with files and array list

hi every one .. i'm an it student , and it's time to finish my final project in java , i've faced too many problems , this one i couldn't solve it and i'm really ubset ! :S my code is like this : in Admin class : public ArrayList cos_info = new ArrayList(); public ArrayList cas_info = new ArrayList(); public int cos_count = 0 ; ...

File Hierarchy system with a web application logic question: List searching

I need to search through a list of folders that could have more folders inside it, and add a new folder depending what folder is its parent.(the path is stored as a String for eg = "root/MyCom/home/") Then i fill in a field with a new folder name and add it to the final folder(eg "home/"). Below as you can see , I can navigate to the r...

List Question in Java

Hello All, I have a following ArrayList, [Title,Data1,Data2,Data3] [A,2,3,4] [B,3,5,7] And I would like to convert this one like this, [Title,A,B] [Data1,2,3] [Data2,3,5] [Data3,4,7] I'm bit confused with the approach. Any hint would be much appreciated. Thanks. ...

Vb.NET String.Format with ArrayList

Hi, I'm trying to use an arraylist as the parameter to String.Format. msg = msg & String.Format("<td>{0}</td>" & _ "<td>{1}</td>" & _ "<td>{2}</td>" & _ "<td>{3}</td>" & _ ...

Why I get UnsupportedOperationException when trying to remove from the List?

I have this code: public static String SelectRandomFromTemplate(String template,int count) { String[] split = template.split("|"); List<String> list=Arrays.asList(split); Random r = new Random(); while (list.size()>count) { list.remove(r.nextInt(list.size())); } return StringUt...

how do i return arraylist from a function?

Hi guys, I learnt example from msdn to populate a listbox control with arraylist. http://msdn.microsoft.com/en-us/library/1818w7we(v=VS.100).aspx I want to create a function which will give return the USStates arraylist and use the returned value as datasource for listbox1 Dim USStates As New ArrayList() USStates.Add(New USSta...