Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2011
    Messaggi
    106

    [java] hashset VS linkedhashset

    Ragazzi ho letto le differenze tra queste 2 strutture (nell api di java )ma non ho capito molto.
    Facendo anche parecchie prove ho visto che tutte e 2 le strutture( passandogli dei valori interi a caso), quando vado a stampare iterando valore per valore,hanno un risultato assolutamente uguale cioè vengono stampati in valori cosi nell'ordine in cui sono stati inseriti.
    -Quindi la mia domanda è : la differenza sta semplicemente nell velocita di ricerca, cancellazione ecc??
    -Le ci sono delle differenze che non vedo?

  2. #2

    Re: [java] hashset VS linkedhashset

    Originariamente inviato da albymotard
    Ragazzi ho letto le differenze tra queste 2 strutture (nell api di java )ma non ho capito molto.
    Facendo anche parecchie prove ho visto che tutte e 2 le strutture( passandogli dei valori interi a caso), quando vado a stampare iterando valore per valore,hanno un risultato assolutamente uguale cioè vengono stampati in valori cosi nell'ordine in cui sono stati inseriti.
    -Quindi la mia domanda è : la differenza sta semplicemente nell velocita di ricerca, cancellazione ecc??
    -Le ci sono delle differenze che non vedo?
    La differenza è nell'implementazione: la prima si basa sugli array, mentre la seconda su strutture collegate.

    Le due strutture hanno la medesima finalità.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2011
    Messaggi
    106

    [JAVA] differenze hashXXX - linkedXXX

    Ciao ragazzi volevo avere qualche info in piu sulle differenze tra :
    hashMap linkedHashMap
    hashSet linkedHashSet
    hashTable linkedHashTable
    Non capisco quali motivi mi possono portare ad usare una hasXXX o una linkedXXX. Quali sono i benefici di una lista linkata?? Io ho fatto delle prove su queste 6 strutture, analizzando l'out ho visto che la hashMap fa la stessa cosa di linkedHashMap, hashSet fa la stessa cosa di linkedHashSet, ecc.

  4. #4
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    guardando le API

    hashmap
    e linkedhashmap

    qualcosa dovrebbero dirti riguardo alle 2.
    Sceglierne una? dipende da quello che devi fare
    RTFM Read That F*** Manual!!!

  5. #5
    Utente di HTML.it
    Registrato dal
    Jun 2011
    Messaggi
    106
    si ma le differenze...tutto cio' che è hashXXX che differenza ha con linkedhashXXX? capito?
    cioè le 3 strutture hashmap, hashSet, hashTable in cosa differiscono con la linkedXXX. quelle 3 strutture vengono ripetute ma con la differenza che utilizza le listelinkate..csa cambia? cosa fanno in più le liste linkate?

  6. #6
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    Le differenze sono quelle (e non mi par poco).
    LinkedHashMap

    Hash table and linked list implementation of the Map interface, with predictable iteration order. This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order).

    HashMap


    Hash table based implementation of the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

    This implementation provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets. Iteration over collection views requires time proportional to the "capacity" of the HashMap instance (the number of buckets) plus its size (the number of key-value mappings). Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important.


    HashSet invece non deriva da Map ma da Set e per set vale A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction.

    Infine LinkedHashSet

    Hash table and linked list implementation of the Set interface, with predictable iteration order. This implementation differs from HashSet in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is the order in which elements were inserted into the set (insertion-order). Note that insertion order is not affected if an element is re-inserted into the set. (An element e is reinserted into a set s if s.add(e) is invoked when s.contains(e) would return true immediately prior to the invocation.)

    trovo la javadoc molto molto esplicita a riguardo
    RTFM Read That F*** Manual!!!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.