w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
cookies get vanished when browser closed in codeiginter
The value of expire should be a number only. Don't add the current time as the value passed is the number of seconds it should persist for from now. See the documentation for more details.

Categories : PHP

All forms and code vanished from Access database
The first thing to attempt is to open the database and choose Compact and Repair. I would then go into the VB Editor, if possible, and choose the Debug menu, Compile. While in the VB Editor, also check Tools, References for any missing references. If the database is split to a back-end and front-end then just give them a new copy of the front-end. If this doesn't work then I would re-install Office on their computer. If they have their own copy of the database (it is not split) then give them a new copy. If they have already entered data that needs to be kept then I would start a new database and import all of the Access objects from the existing database. I have found that re-importing all objects solves most of these issues. You could import just the tables from their copy of the data

Categories : Ms Access

Move an item from one list/arraylist to another list/arraylist
It will be easier for you to use ListModel as suggested by MadProgrammer You can try like this model = new DefaultListModel<String>(); for(String str : playlist){ model.addElement(str); } listPlaylist.setModel(model); listPlaylist.setSelectedIndex(0); You can create two models for library and playlist and perform operations

Categories : Java

Package name and its effect on search results for Android-- My app has vanished
Search your app in Appbrain Apptimizer. It helps you to improve your search ranking. The play store's ranking system is pretty unconventional. You need downloads + description length + ratings and many more things which I may never know.

Categories : Android

adding 1 to an ArrayList item
ArrayList would be overkill for this. But if you must, (untested code) First initalize your array to contain 13 elements (0 to 12) so that IndexOutOfBoundsException won't pop up. They would be initialized to zero. results = new ArrayList<Integer>(13); Then just get the element, add one, and set it results.set(dicetotal, results.get(dicetotal) + 1); Indeed, you should just use an int[] if you know the size of the array beforehand, and won't change during the program. They are faster than ArrayList. // initialize results = new int[13]; // could be new int[11]; if you put results in array elements 0 to 10. // ... // add to tally results[dicetotal]++; // or, instead, pack the array because dice roll results can only be in 2 to 12. // Put such results in array element 0 to 1

Categories : Java

My ArrayList only contains the last item on my array
You're overwriting the variables id, yr, fname, ... constantly on each loop iteration. These variables are probably also directly used as fields in the Student class. Try to use a fresh variable each loop iteration. for(int z = 0; z < stringList.length; z++){ p = stringList[z].split(","); int id = Integer.parseInt(p[0]); int yr = Integer.parseInt(p[5]); String fname = p[1]; String gname = p[2]; char mname = p[3].charAt(0); String course = p[4]; Student stud = new Student(id,yr,fname,gname,mname,course); System.out.println(id +" "+ yr +" "+ fname + " "+gname + " "+mname + " "+course +" should be the same with : " +stud.toString()); list.add(stud); // add the student object to the list } //end of the for loop

Categories : Java

How do I Add Item ArrayList in Another Activity?
If I understand your question correctly and you want to add items to ArrayList defined in one Android Activity from another, you can just make this ArrayList static and add a static public method to your MainActivity: public static void addItem(CustomObject object) { yourArrayList.add (object); } And then call it from any Activity you want: MainActivity.addItem(some_object)

Categories : Android

How to Add an item to ArrayList and Dictionary using reflection
To add an Item to a Generic.List<T> you use the Add method Example: MyArray.Add(1); For Generic.Dictonary<T> you also use the Add method, but supply 2 values, Key and Value MyDictionary.Add("MyKey", "MyValue"); So you can just loop though your PropertyInfo[] and add whatever you need to your List<T> or Dictionary<T> foreach(var prop in properties ) { MyArray.Add(a number from somewhere); MyDictionary("some key", "some value"); }

Categories : C#

Getting only the last item data from hashmap arraylist
you should have to put new HashMap inside your current HasHMap so you can get subcategories items for particular index. see this for how to use nested HashMap? and use it in subcategories loop. i am using ArrayList of getter setter class to bind the data. so if you can convert your code into arraylist and edit the question that will be a great.. and see below code import java.util.ArrayList; public class MainCategories extends Fragment { WebserviceClass wservice = new WebserviceClass(); Context c; View v; String data = ""; String User_id, countryid; JSONObject jobj; JSONArray datas; int currentpage = 1; ArrayList<HashMap<String, String>> dataList = new ArrayList<HashMap<String, String>>(); // testAdapter adapter ArrayList<Allcategories> listing = new A

Categories : Android

Addition item in ArrayList during the course of the program
private void createCircles() { mCircles = new ArrayList<Circle>(); mCircles.add(new Circle(120, 30, 7)); } This Creates a new ArrayList<Circle> every time it is called, writing over whatever circles it has. If you mean to instantiate the ArrayList instead of wipe it, try this: private void createCircles() { if (mCircles == null) { mCircles = new ArrayList(); } mCircles.add(new Circle(120, 30, 7)); } This should instantiate the ArrayList whenever it is null only. Also, if you are testing this by looking at the GUI of this, the circles may be stacking. This means that it maybe making the circles just fine but at the same time, not showing them, because they all have the properties of (120, 30, 7). Consider placing them randomly, or in set different locations

Categories : Java

Safely removing an item from a Java ArrayList
From what I see, you are removing items with =null on the actual Object. And that is wrong. ArrayList has an its own remove() method which you should use. It automatically removes the object and reduces the size of the list.

Categories : Java

`ArrayList of HashMap` or `LinkedHashMap` to get item by index
Try using SortedMap. For example: SortedMap<Key, Value> map = new TreeMap<Key, Value>(); This way you get the fast lookup time (via key), but they also remain ordered. You can then iterate over the data like so: for(Key k : map.keySet()) { process(map.get(k)); } I used them recently to analyze 10s millions tweets where the key was a date, and the value was a counter. I wanted to maintain the ordering of the dates. update If you can get by with just itereating over the data, then my method will suffice. Perhaps you could supply a small example? If it's absolutely required that you can reference the data by index as well, it seems like you would just want to maintain two datastructures like @Jim mentioned. I'ved had to do that before.

Categories : Java

In markup page it takes only the first Item of an ArrayList
declare a like this in code behind int a { get { if (ViewState["a"] == null) { ViewState["a"] = 0; } return Convert.ToInt16(ViewState["a"]); } set { ViewState["a"] = value; } } protected void Page_Load(object sender, EventArgs e) { // construct a scheduler factory if (!Page.IsPostBack) { a = 3; } }

Categories : C#

Does editing an item in an arraylist count as modifying the list?
Only changes to the list contents (what objects are in the list) will count as a list modification. Changes to the internal state of the objects in the list will not change the list modification counter. In pathological cases, I suppose, changing the internal state of a list element might indirectly trigger a change to the list itself as a side effect. My first paragraph assumes that nothing like that is going on.

Categories : Java

PlayFramework [NullPointerException: null] when add an item in ArrayList or HashMap
The User class seems irrelevant here. If countriesVisited were null, the @for loop would already fail. The method ArrayList.contains accepts null arguments and won't ever throw any NullPointerException unless there's something wrong with the elements equals methods. It looks like countries simply is null. Check the return value of Country.find.all().

Categories : Java

Comparison: Runtime of LinkedList addFirst() vs. ArrayList add(0, item)
As per my knowledge, Arraylist add operaion runs in O(1) time, so the results of your experiment are correct. I think the constant time for arrayList add method is amortized constant time. As per java doc : adding n elements require O(N) time so that is why the amortized constant time for adding.

Categories : Java

Null Pointer Exception - Adding item to ArrayList
The arrayList must be initialized! : ) public ArrayList<Walls> walls = new ArrayList<Walls>(); Edit: True that the conventional way to declare such a field is to use the interface as type like so: public List<Walls> walls = new ArrayList<Walls>();

Categories : Java

Android - Returning a position of an item in an ArrayList that appears multiple times
One for loop is enough in this case. This will some thing like: isExist = false; for(index = 0; index<variantArray.size(); index++){ if(variantArray.get(index) == userChoiceVariant && unitArray.get(index) == userChoiceUnit){ //update quantity isExist = true; } } if(!isExist){ //insert order }

Categories : Android

How much faster will a .contains() method be for a Hashtable,boolean> than an ArrayList>?
Little excerpt from the Javadoc comment of ArrayList: The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation. That means, the get operation on your second list runs in constant time O(1), which should be ok from a performance point of view. But the contains and the remove operation (on the first list) run in linear time O(n). Calling these operations as many times as the second list's size could last very long, especially if both lists are large. Using a hashing data structure for the first one would re

Categories : Java

What is the difference between ArrayList, ArrayList, ArrayList?
ArrayList<?> means "an ArrayList instance containing a type which is to be determined" ArrayList is the class of an ArrayList An ArrayList<Object> means an instance of ArrayList containing Object types. This looks like it could be a good write-up on this (and more): http://docs.oracle.com/javase/tutorial/java/generics/types.html

Categories : Java

Pass an ArrayList as an argument to a method, process the arrayList and return it - Java
The Problem I'd say there are some bad practices in your code, such as disregarding the generics in ArrayLists, but let's get to the point. It seems to me, that your problem is in the following method: public ArrayList detectPingPongArray( int threshold_access_session_time, int threshold_transition_time, ArrayList<Dados> dadosSTA ) { dadosArray=dadosSTA; for(int i = 1; i<arrayDeDados.size()-1; i++) { dadosArray.get(i).setPingPong(); } return dadosArray; } This is your code, just with a different formatting to fit in the answer. The method receives an ArrayList<Dados> dadosSTA, which you assign to dadosArray. You return this same variable, and you want to perform modifications on it. However, you are iterating over arrayD

Categories : Java

Convert Arraylist to Array, data of Arraylist is of custom class type
ArrayList<String> stock_list = new ArrayList<String>(); stock_list.add("stock1"); stock_list.add("stock2"); String[] stockArr = new String[stock_list.size()]; stockArr = stock_list.toArray(stockArr); for(String s : stockArr) System.out.println(s); this is helpful for arraylist to array conversion also you can use arraylist directly with the arrayadapter no need to convert it to array

Categories : Android

Java arraylist - Check if the two items in arraylist index are set while generating random ints from list?
ArrayList#contains compares a Object with those objects contained within the list... Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)). Your list contains arrays of int, which aren't easily comparable. It would be much easier if you used a Object whose equals method was capable of comparing the coordinates of other similar objects. Something like... public class Coordinate { private int latitude; private int longitude; public Coordinate(int latitude, int longitude) { this.latitude = latitude; this.longitude = longitude; } public int getLatitude() { return latitude; } public int getLongitu

Categories : Java

Java 3d ArrayList subMatrix modification alters other subMatrices of the 3d ArrayList
ArrayList<ArrayList<Integer>> mirror = new ArrayList<ArrayList<Integer>>(unmirrored); This line does not make a deep copy of all the elements in it. It does create a new instance of an ArrayList, but all its the elements are the same instances of ArrayList<Integer> as were present in the unmirrored instance. So changing those elements with mirror.get(j).set(i, mirror.get(i).get(j)); does change the same instance mirror.get(j) and unmirrored.get(j). I.e., mirror.get(j) == unmirrored.get(j).

Categories : Java

Selection of First L Items of ArrayList of size N > L and Insertion to Another ArrayList in Java
You can use List.subList(int, int) method to get the first L items int L = 2; List<String> newList = new ArrayList<>(inputList.subList(0,L));

Categories : Java

Repeat multiple lines in an ArrayList and add them in order back to the same ArrayList
Here's some code to achieve this: ArrayList<String> list = new ArrayList<String>( Arrays.asList("02, String1", " 03, Num1", " 03, Num2", " 02, String2")); int numberOfTimes = 4; // always starts and ends with 02, so this is sufficient int count3s = list.size() - 2; String last = list.remove(list.size() - 1); // remove last 02 // optimization to prevent repeated resizing of the array list.ensureCapacity(2 + numberOfTimes * count3s); // we already have them once, so just repeat numberOfTimes-1 times for (int i = 0; i < numberOfTimes-1; i++) for (int j = 0; j < count3s; j++) list.add(list.get(j+1)); list.add(last); // add last 02 back System.out.println(list); Prints: [02, String1, 03, Num1, 03, Num2, 03, Num1, 03, Num2, 03, Num1, 03, Num2, 03, Num1,

Categories : Java

Java - new ArrayList(List) vs empty ArrayList() + add(element)
The performance difference is likely to be 30 - 300 ns depending on your system and how warmed up your code is. I suspect the performance difference is small. I always say, if in doubt; write the code as simpler and clear as you can and it will often perform ok as well.

Categories : Java

How to create ArrayList (ArrayList) from array (int[]) in Java
The problem in intList = new ArrayList<Integer>(Arrays.asList(intArray)); is that int[] is considered as a single Object instance since a primitive array extends from Object. This would work if you have Integer[] instead of int[] since now you're sending an array of Object. Integer[] intArray = new Integer[] { 0, 1 }; //now you're sending a Object array intList = new ArrayList<Integer>(Arrays.asList(intArray)); From your comment: if you want to still use an int[] (or another primitive type array) as main data, then you need to create an additional array with the wrapper class. For this example: int[] intArray = new int[] { 0, 1 }; Integer[] integerArray = new Integer[intArray.length]; int i = 0; for(int intValue : intArray) { integerArray[i++] = intValue; } intList =

Categories : Java

compare two arrayList and stock the result in a thirth arrayList
You can just use ArrayList.retainAll method like this list1.retainAll(list2) after this method list1 will containt only the data which are available in list2.

Categories : Java

Accessing specific ArrayList elements, when the ArrayList changes frequently
arraylist.get(8 - numberOFDeletedElements); 8 not 9 since indexing starts with 0 and 9th element in the beginning (before deletion) has index 8 or arraylist.get(arraylist.size() - 2); You might not need this at all. Since all the objects are same. If they are different then you might need to iterate over array and check conditions on which you want to find an element

Categories : Java

Accessing data from an Arraylist stored in an Arraylist - Java
I hope your got your question right: for(ArrayList<String> arr: SGenresMaster){ //arr can be any array from SGenresMaster for(String s : arr){ //do something } } or SGenresMaster.get(index).get(someOtherIndex);

Categories : Java

Best way to find the largest value in a Hashmap
You can loop over the map's values(): ArrayList<String> max = null; for (ArrayList<String> list : map.values()) { if (max == null || list.size() > max.size()) max = list; } To get the key associated with the largest value: ArrayList<Integer> maxKey = null; int maxLen = 0; for (Entry<ArrayList<Integer>, ArrayList<String>> e : map.entrySet()) { int len = e.getValue().size(); if (maxKey == null || len > maxLen) { maxKey = e.getKey(); maxLen = len; } }

Categories : Java

ArrayOutOfBoundsException when accessing ArrayList inside ArrayList
This loop: for(int i = 0; i < arrays.size(); i++){ ArrayList<Float> aux = new ArrayList<Float>(); arrays.add(aux); } will not even execute once. Since arrays.size() is 0. So, your arrays is empty only. And hence you get that exception. I guess you need to change your loop to: for(int i = 0; i < numKeys; i++) Apart from that, I would do some changes in your code: I would declare my list as: List<List<Float>> arrays = new ArrayList<List<Float>(numKeys); Also, be sure you know why you are passing that parameter to ArrayList constructor. That is used for setting initial capacity of ArrayList. It doesn't fix it's size as in case of arrays. You can skip that parameter, if your ArrayList is not going to be very large. I would use HashMa

Categories : Java

ArrayList IndexOutOBoundsException after removing an object from ArrayList
Your problem is that you iterate over sorted collection and removing from word list. for(j=i;j<sorted.size();j++){ ... word.remove(j); // and now word is shorter than sorted } you probably need to have j<word.size()

Categories : Java

Find the value that matches using ArrayList.contains() and them remove it from the ArrayList
List.removeAll() method will do the task b.removeall(al) it removes from this list all of its elements that are contained in the specified collection (optional operation). is this what you want?

Categories : Java

Persisting an ArrayList - cannot convert from Object to ArrayList
If the file does not exist, then Persister.restore does, in fact, return a new Object(), which is not an instance of ArrayList. You can do this instead: public static ArrayList<String> restore(String fileName){ File file = context.getFileStreamPath(fileName); ArrayList<String> obj = null; // returning null indicates error if(file.exists() && file.length()>0){ FileInputStream fis = null; ObjectInputStream ois = null; try { fis = new FileInputStream(file); ois = new ObjectInputStream(fis); obj = (ArrayList<String>) ois.readObject(); ois.close(); fis.close(); } catch (IOException ex) { ex.printStackTrace(); } catch (ClassNotFoundException e

Categories : Android

returning an arraylist of arraylist from a resultset in java
Like this: List<List<String>> result = new ArrayList<>(); // List of list, one per row ... while (resultset.next()) { List<String> row = new ArrayList<>(numcols); // new list per row int i = 1; while (i <= numcols) { // don't skip the last column, use <= row.add(resultset.getString(i++)); } result.add(row); // add it to the result }

Categories : Java

This item is unreachable because a previous item (item #1) is a more general match than this one
During each state change, the state list is traversed top to bottom and the first item that matches the current state is used—the selection is not based on the "best match," but simply the first item that meets the minimum criteria of the state. http://developer.android.com/guide/topics/resources/drawable-resource.html Your first item matches always, place it at the end instead

Categories : Android

Circular ArrayList (extending ArrayList)
What you described is basically getting the modulus of the index you want, and accessing that element in a list. You could do the following with composition over inheritance: Create a wrapper class for the interface List<T>, let's call it ListWrapper now add a constructor accepting instance of List let the List instance be protected, and name it to wrapped Extend the wrapper class Why do all this crap? This is implementation agnostic. One day, you might want to use this convenience on another implementation. Then you'll have to duplicate code, and hell begins. If you need a 3rd implementation too, and then add just one tiny bit of new functionality, you are doomed. With a wrapper class in between: you can have all classes implementing the List interface to have your own fun

Categories : Java

Removing items in an arraylist from another arraylist in VB.NET
Instead of using an ArrayList, use a Dictionary or HashTable to save the file names from your query. Your inArray function is doing a O(n) table scan for every file found, which is quite slow. Both Dictionaries and HashTables has a Contains member that will search your file names at a significantly faster rate.

Categories : Sql Server



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.